Published on 01/03/2023
As of ES6, we are able to set default parameter values when defining a function, as shown below:
This allows for named parameters to be initialized with default values if no value is present or it evaluates to undefined.
If you want to call a function without passing one of the parameters, allowing it to fall back to the default, you need to explicitly pass undefined in it's place, as shown below:
One caveat to keep in mind is that this is order-dependent (without using destructuring).
At the time of publishing this post, this feature has been around for a while and has pretty solid browser support.
ES6 For Everyone - course by Wes Bos
---
Category: JavaScript