From ES6/ES2015, default parameters is in the language specification.
Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed.
We can also simulate default named parameters via destructuring:
There are a lot of ways, but this is my preferred method - it lets we pass in anything we want, including false or null.
This assigns to delete_after the value of delete_after if it is not a falsey value otherwise it assigns the string "my default here". For more detail, check out Doug Crockford's survey of the language and check out the section on Operators .
This approach does not work if we want to pass in a falsey value i.e. false, null, undefined, 0 or "".
When dealing with a number of parameters to a function, it is often useful to allow the consumer to pass the parameter arguments in an object and then merge these values with an object that contains the default values for the function
WE find something simple like this to be much more concise and readable personally.
In ECMAScript 6 we will actually be able to write exactly what we have:
This will set delete_after to false if it s not present or undefined. We can use ES6 features like this one today with transpilers such as Babel.