ES6: Default Parameters
3min read
Default paramters in a function are preset parameters, which are used when no arguments are provided in the function call that overwrites them. ES6 provides us with an easy way to declare them, a feature which many developers missed and other languages natively offer.
Prior to ES6 when developers wanted to declare default parameters on a function they would define them as variables within the function and set the value of the variable equal to the equivalent parameter or a default value.
ES5
ES6
In ES6 we can declare the default parameters simply in the function declaration by setting the paramter equal to a default value.
Leave a Reply
Want to join the discussion?Feel free to contribute!