When the passed parameter is less than the number of parameters defined in the function prototype, it is assigned the value of undefined. To set default values for the parameters not passed during the function call, or to set default values for fields not present in a JSON object, the above method is popular.
variable ?? default_value
Below are examples of the Nullish Coalescing Operator.
Example 1: In this example, we will see a basic function using the nullish coalescing operator
Example 2: The more common use case is to set default values for JSON objects as follows.
Value of bar: 0 Value of baz: 42
- Google Chrome 80
- Firefox 72
- Edge 80
- Opera 67
- Safari 13.1
Please Login to comment...