Hi Naveen, I have a doubt here, In javascript there is no need to match the exact parameters of the method when calling it?
@rathishramankutty302 Жыл бұрын
But what if i want to pass only 2nd or 3rd parameter in the function when i run it? it has to be in the same order how they are defined.
@brucehill9710Ай бұрын
Yes, the parameters have to be in order. Javascript does allow optional parameters; so you can define defaults to the parameters in the function to make then optional, but usually the optional parameters are at the end so they can be simply left off and get their default values. If you provide a default for the first parameter but you want to pass the 2nd and 3rd parameter to the function, you will have to call the function with undefined as the first parameter. But it is better practice to put the optional parameters at the end, after the required parameters.