Is it possible to overload functions/methods in JS like in C#?
Trying to overload functions in JS if possible to take different number of arguments.
Is it possible to overload functions/methods in JS like in C#?
Trying to overload functions in JS if possible to take different number of arguments.
3
Answers
No. Not possible with regular JavaScript.
You can with typescript — see https://www.typescriptlang.org/docs/handbook/2/functions.html
In JavaScript, you cannot natively overload functions or methods in the same way as you can in C#. But you can achieve similar functionality by checking the number or types of arguments passed to a single function:
Unfortunately JavaScript does not have support for direct overloaded functions.
Something close you can do is structure/array unpacking: