This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to set default value if null in Javascript.
Let’s say you have a null variable named ‘a’ with the value null.
var a = null;
In order to set a default value, you can use the nullish coalescing operator ??
.
var a = null;
console.log(a ?? "a is null");
Note: The nullish coalescing operator ??
is a logical operator that functions by returning the value on its right side if the value on its left side is null
or undefined
. Else, it will return the value on its left side.
The post How to Set Default Value If Null in Javascript appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-17T12:16:59+00:00) How to Set Default Value If Null in Javascript. Retrieved from https://www.scien.cx/2021/02/17/how-to-set-default-value-if-null-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.