In TypeScript, function overloading is a mechanism or ability which create multiple methods with the same name and with a different number of parameters or types. Function overloading is also known as method overloading.
Method overloading is allowed when -
Suppose we have to perform multiplication of the given numbers, but there can be a different number of parameters. If we write the method such as mul_a(number, number) for two parameters, and mul_b(number, number, number) for three parameters, then it may be difficult for us as well as other programmers to understand the behavior of the method because its name differs. In that case, function overloading is used which increases the readability of the program.
Advantage of function overloading
In the above example:
Addition: Hello JavaTpoint Addition: 50
Example of function overloading in a class:
Result: 101 Length of String: 10
Function overloading with a different number of parameters and different types along with the same function name is not supported.