Default functions parameters
When declaring a function,
a default value can be assigned to any argument
In every case the argument will not be sent while
calling the function, the default will be assigned
fucntion calculate(a,b = 3) {
return a*b;
}
calculate(2,2);
//will return 4
calculate(2);
//will return 6 (2 sent * 3 default)
-
The default value(s) can be everywhere in the declaration of the function
-
While calling the function, multiple values can be discarded, only if:
-
All are defined as defaults in the declaration
-
Not the first is missing from the call
-
All missing values are the conscutive last values
back to main page