So in this case the foo(arg1) was overwritten by foo(arg1,arg2), but we only passed one
Argument (“Geeks”) to the function. It means that the second argument is undefined, So when we tried to print the second argument, it is printed as “undefined”.
Function1 called with arguments : Geeks Geeks Function2 called with arguments : Geeks and for Geeksfor Function3 called with this array as an argument : [ Geeks for Geeks] GeeksforGeeks Output of log is : GeeksforGeeks
In the above program, when different number of arguments are passed to the same function, then based on the number and type of arguments, the arguments will be passed to the respective function.
In this case, we have used three different functions (function1, function2, function3) for function Overloading.