Reputation: 631
Why the following code ends up with the function with the most parameters get called - function foo (a, b, c)?
function foo (a) {
console.log("single parameter function")
};
function foo (a, b) {
console.log("two parameter function");
}
function foo (a, b, c) {
console.log("three parameter function");
}
foo("hello", "goodbye");
Upvotes: 0
Views: 312
Reputation: 522042
Function overloading is not a thing in Javascript. A function name can only be defined once. You don't actually have three different versions of foo
, you have one: the last one declared.
Upvotes: 3