 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements
 