Learning JavaScript ES6: Part 3: Default Parameter Values

Learning JavaScript ES6

JavaScript ES6 (ECMAScript 6) is a newer specification for JavaScript introduced in 2015 and adopted by most browsers starting in mid-2016. It added new syntax and a greater ability to use object-oriented programming in JavaScript.

Default Parameter Values

In previous versions of JavaScript, testing for parameter values required as many lines as parameters to a function. Any “default” values needed to be tested against those passed to a function.

In JavaScript ES6, this issue has been addressed through default parameter values.

Using Default Parameter Values

To set the default values of any parameter values, the use of the assignment operator can be used within the parameter list of the function itself. This make the function declaration longer, but it is still less code than the multiple lines the previous approach needed.

Play with the example on Repl.it!