ES6 basis - the default parameters Default Parameter Values

In ES6 which we can go to the function accepts arguments developed a default value, in the implementation of this function, if the value of the parameter of the function is not specified, will use the default values ​​of these parameters

 

example:
function breakfast(dessert = 'cake',drink = 'tea'){
return `${dessert} ${drink} `
}
console.log(breakfast()); //cake tea
 
There is no function to set the parameters, the use of the default value; if the parameter is set, the value of the parameter set is used.

 

example:
function breakfast(dessert = 'cake',drink = 'tea'){
return `${dessert} ${drink} `
}
console.log (breakfast ( 'bread', 'beer')); // steamed beer
 

Guess you like

Origin www.cnblogs.com/fe-cherrydlh/p/11025051.html