JavaScript Default Parameters

Learn all about JavaScript Default Parameters in this ES6 tutorial.

JavaScript Default parameters used to be one of those things you had to manage manually in your function definitions by checking whether the value passed in was falsy or not. If it was then you can specify an initial value to use and thereby set default parameters. With the advent of ES6, it became easier to set these default parameters in JavaScript by simply allowing coders to specify what value should be put into a parameter if nothing is passed in to the function call. In this ES6 tutorial you’ll learn how the old ES5 way of handling default parameters in JavaScript used to work and some of the issues that this caused. You’ll then see the brand new ES6 syntax which will allow you to easily set those values as default parameters in your JavaScript function definitions. There’s one thing to watch out for though and that is the ordering of your default parameters. To finish off this ES6 Tutorial I will show you what can happen if you don’t pay attention to the order that you define your JavaScript default parameters! If you have multiple JavaScript default parameters in your function definition then you’ll find that you need to specify parameters which are mandatory at the end of the function signature. This is because JavaScript won’t know which parameter you are intending to omit and to which ones should pick up the default parameters value.