SlideShare a Scribd company logo
NULLISH
COALESCING
IN JAVASCRIPT
Nullish Coalescing “??”
The nullish coalescing operator (??) is a logical
operator that returns its right-hand side operand when
its left-hand side operand is null or undefined.
Syntax,
leftExpr ?? rightExpr
Note: It is not possible to combine both the AND ‘&&’
and OR operators ‘||’ directly with ‘??’.
null || undefined ?? ; // raises a SyntaxError
However, to solve it we need to provide parenthesis
explicitly,
(null || undefined) ?? ; // returns
Problem with ||
0 || //
‘’ || //
false || //
undefined || //
null || //
NAN || //
Solution with ??
0 ?? // 0
‘’ ?? // ‘’
false ?? // false
undefined ?? //
null ?? //
NAN ?? // NAN
How “||” different from “??”

More Related Content

PPT
On Scala Slides - OSDC 2009
PDF
Version comaparison in JavaScript
PDF
Currying in JavaScript
PDF
JS Testing Frameworks
PDF
Cool usage of Encoding and Decoding a URI in Javascript
PDF
Iterables and Iterators in JavaScript
PDF
String comparison in javascript
PDF
JavaScript symbols
On Scala Slides - OSDC 2009
Version comaparison in JavaScript
Currying in JavaScript
JS Testing Frameworks
Cool usage of Encoding and Decoding a URI in Javascript
Iterables and Iterators in JavaScript
String comparison in javascript
JavaScript symbols

More from Ideas2IT Technologies (20)

PDF
Json.parse() in JavaScript
PDF
Bubble sort in Java Script
PDF
Performance analysis in merging arrays - JavaScript
PDF
Conditionally add keys in JavaScript
PDF
What is Big O in JavaScript - Part-1
PDF
Variable hoisting in JavaScript
PDF
Formidable ES6 spread operator in JavaScript
PDF
Logging in JavaScript - Part-5
PDF
Logging in JavaScript - Part-4
PDF
Logging in JavaScript - Part-3
PDF
Logging in JavaScript - part-2
PDF
Logging in JavaScript - part-1
PDF
Array vs set in JavaScript
PDF
Arguments Object in JavaScript
PDF
Pollyfills in JavaScript
PDF
Async await in JavaScript - part-3
PDF
Async await in JavaScript
PDF
Regex Cheat Sheet in JavaScript - part-2
PDF
Regex cheatsheet part-1
PDF
Difference between promise-chain and promise.all() in Javascript
Json.parse() in JavaScript
Bubble sort in Java Script
Performance analysis in merging arrays - JavaScript
Conditionally add keys in JavaScript
What is Big O in JavaScript - Part-1
Variable hoisting in JavaScript
Formidable ES6 spread operator in JavaScript
Logging in JavaScript - Part-5
Logging in JavaScript - Part-4
Logging in JavaScript - Part-3
Logging in JavaScript - part-2
Logging in JavaScript - part-1
Array vs set in JavaScript
Arguments Object in JavaScript
Pollyfills in JavaScript
Async await in JavaScript - part-3
Async await in JavaScript
Regex Cheat Sheet in JavaScript - part-2
Regex cheatsheet part-1
Difference between promise-chain and promise.all() in Javascript
Ad

Recently uploaded (20)

PDF
System and Network Administration Chapter 2
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
top salesforce developer skills in 2025.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Introduction to Artificial Intelligence
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administration Chapter 2
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
top salesforce developer skills in 2025.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Introduction to Artificial Intelligence
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
VVF-Customer-Presentation2025-Ver1.9.pptx
Design an Analysis of Algorithms I-SECS-1021-03
CHAPTER 2 - PM Management and IT Context
Wondershare Filmora 15 Crack With Activation Key [2025
Operating system designcfffgfgggggggvggggggggg
PTS Company Brochure 2025 (1).pdf.......
Design an Analysis of Algorithms II-SECS-1021-03
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Odoo Companies in India – Driving Business Transformation.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Ad

Nullish coalescing in JavaScript

  • 2. Nullish Coalescing “??” The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined. Syntax, leftExpr ?? rightExpr Note: It is not possible to combine both the AND ‘&&’ and OR operators ‘||’ directly with ‘??’. null || undefined ?? ; // raises a SyntaxError However, to solve it we need to provide parenthesis explicitly, (null || undefined) ?? ; // returns
  • 3. Problem with || 0 || // ‘’ || // false || // undefined || // null || // NAN || // Solution with ?? 0 ?? // 0 ‘’ ?? // ‘’ false ?? // false undefined ?? // null ?? // NAN ?? // NAN How “||” different from “??”