Overloading: which is the ability of a single function to have multiple signatures.
That means JavaScript functions don’t actually have signatures. A lack of function signatures also means a lack of function overloading. Look at what happens when you try to declare two functions with the same name
(see next code running here -> https://playcode.io/664865)
function sayMessage(message) { console.log(message); } function sayMessage() { console.log("Default message"); } sayMessage("Hello!"); // outputs "Default message"
In JavaScript, however, when you define multiple functions with the same name, the one that appears last in your code wins. The earlier function declarations are completely removed, and the last is the one that is used. Once again, it helps to think about this situation using objects:
var sayMessage = new Function("message", "console.log(message);"); sayMessage = new Function("console.log(\"Default message\");"); sayMessage("Hello!"); // outputs "Default message"
THE PRINCIPLES OF OBJECT-ORIENTED JAVASCRIPT. Copyright © 2014 by Nicholas C. Zakas