JavascriptWeb DevelopmentFront End Technology

Function overloading occurs when a function performs different tasks based on a number of arguments passed to it.

The best practice for function overloading with parameters is to not check the types. The code runs slower when the type is checked and it should be avoided. For this, the last parameter to the methods should be an object

Also, do not check the argument length.

Example

Here’s an example −

function display(a, b, value) {
}
display(30, 15, {"method":"subtract"});
display(70, 90, {"test":"equals", "val":"cost"});
Published on 31-Jan-2018 07:10:16