ES6 provides a new syntax that can be used to define default values to function parameters:
{
console.log(x, y, z); // Output "6 7 3"
}
myFunction(6,7);
Also, passing undefined
is considered as missing an argument. Here is an example
to demonstrate this:
{
console.log(x, y, z); // Output "1 7 9"
}
myFunction(undefined,7,9);
Defaults can also be expressions. Here is an example to demonstrate this:
{
console.log(x, y, z); // Output "6 7 8"
}
myFunction(6,7);