This article mainly introduced through the example to understand JavaScript has no function overload concept, very easy to understand, the need for friends can refer to the
Imagining the function name as a pointer also helps to understand why there is no concept of a function overload in ECMAScript. The following example:
The code is as follows:
function Addsomenum (num)
{
return num+100;
}
function Addsomenum (num)
{
return num+200;
}
var result=addsomenum (100);//300
Obviously, this example declares two functions with the same name, and the result is that the following function overrides the previous function. The above code is actually consistent with the following code.
The code is as follows:
var addsomenum=function (num)
{
return num+100;
};
var addsomenum=function (num)
{
return num+200;
};
var result=addsomenum (100);//300
By looking at the rewrite code, it's easy to see what's going on. When you create a second function, you actually overwrite the variable addsomenum that references the first function.
The above mentioned is the entire content of this article, I hope you can enjoy.