Lys
Lys

Reputation: 631

function call with arguments less than declared parameters

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

Answers (1)

deceze
deceze

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

Related Questions