
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Is there a ânull coalescingâ operator in JavaScript?
Yes, JavaScript now supports the “null coalescing” operator, but you can also use the concept of logical OR (||). The syntax is as follows −
var anyVariableName=null; var anyVariableName=yourVariableName || yourActualValue;
Example
var fullName=null; console.log("The full name is="+fullName); var actualName=fullName || "David Miller"; console.log("The full name is="+actualName);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo81.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo81.js The full name is=null The full name is=David Miller
- Related Articles
- What is a "null coalescing" operator in JavaScript?
- How to use Null Coalescing Operator (??) in C#?
- Difference between the Ternary operator and Null coalescing operator in php
- Is there a & logical operator in JavaScript?
- Is there any way to check if there is a null value in an object or array in JavaScript?
- Is there a ânot equalâ operator in Python?
- Is there is a standard function to check for null, undefined, or blank variables in JavaScript?
- What is a ternary operator (?:) in JavaScript?
- What is MySQL NULL-safe equal operator and how it is different from comparison operator?
- Is there an equivalent of Câs â?:â ternary operator in Python?
- Is there a Boolean Typed Array in JavaScript?
- What is increment (++) operator in JavaScript?
- What is decrement (--) operator in JavaScript?
- What is Conditional Operator (?:) in JavaScript?
- What is typeof Operator in JavaScript?

Advertisements