How to Set Default Value If Null in Javascript

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 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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to Set Default Value If Null in Javascript." Ariessa Norramli | Sciencx - Wednesday February 17, 2021, https://www.scien.cx/2021/02/17/how-to-set-default-value-if-null-in-javascript/
HARVARD
Ariessa Norramli | Sciencx Wednesday February 17, 2021 » How to Set Default Value If Null in Javascript., viewed ,<https://www.scien.cx/2021/02/17/how-to-set-default-value-if-null-in-javascript/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Set Default Value If Null in Javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/17/how-to-set-default-value-if-null-in-javascript/
CHICAGO
" » How to Set Default Value If Null in Javascript." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/17/how-to-set-default-value-if-null-in-javascript/
IEEE
" » How to Set Default Value If Null in Javascript." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/17/how-to-set-default-value-if-null-in-javascript/. [Accessed: ]
rf:citation
» How to Set Default Value If Null in Javascript | Ariessa Norramli | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.