I have a function
function test(name)
{
}
I call it with test("kanishka");
In one case, I want to pass two parameters (name
and age
) to this function:
test("kanishka",27);
In PHP, I can do this by setting a default value to age
:
test(name , age = NULL)
Is there any way in JavaScript to do this?
I tried
test(name , age = NULL)
but it gives errors.
I can declare 2 functions
test(name) and test(name , age = NULL)
but it duplicates the code.
Or I can change my previous function call which took one parameter to two parameters, giving a default value for age
:
test("kanishka" , 0)
but in this case I have to find all function call and change them.