JavaScript Nullish Coalescing(??) Operator Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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, and otherwise returns its left-hand side operand. It's commonly used to provide default values for variables. Syntax: variable ?? default_valueBelow are examples of the Nullish Coalescing Operator. Example 1: In this example, we will see a basic function using the nullish coalescing operator javascript function foo(bar) { bar = bar ?? 55; console.log(bar); } foo(); // 55 foo(22); // 22 Output55 22 Example 2: The more common use case is to set default values for JSON objects as follows. javascript const foo = { bar: 0 } const valueBar = foo.bar ?? 42; const valueBaz = foo.baz ?? 42; // Value of bar: 0 console.log("Value of bar: ", valueBar); // Value of bar: 42 console.log("Value of baz: ", valueBaz); OutputValue of bar: 0 Value of baz: 42 Supported Browsers: The browsers supported by JavaScript Nullish Coalescing Operator are listed below: Google ChromeEdge FirefoxOperaSafari Nullish Coalescing Visit Course Comment More infoAdvertise with us Next Article Does JavaScript Operators like or ( || ), and ( && ), null coalescing ( ?? ) makes Weak Comparison? K Kriyszig Follow Improve Article Tags : JavaScript javascript-operators Similar Reads Nullish Coalescing Assignment (??=) Operator in JavaScript This is a new operator introduced by javascript. This operator is represented by x ??= y and it is called Logical nullish assignment operator. Only if the value of x is nullish then the value of y will be assigned to x that means if the value of x is null or undefined then the value of y will be ass 2 min read JavaScript Course Logical Operators in JavaScript logical operator is mostly used to make decisions based on conditions specified for the statements. It can also be used to manipulate a boolean or set termination conditions for loops. There are three types of logical operators in Javascript: !(NOT): Converts operator to boolean and returns flipped 3 min read Does JavaScript Operators like or ( || ), and ( && ), null coalescing ( ?? ) makes Weak Comparison? JavaScript operators like logical OR (||), logical AND (&&), and null coalescing (??) are used for making conditional evaluations and performing logical operations in JavaScript. While these operators are commonly used for controlling the flow of the code execution and handling values in the 2 min read What does OR Operator || in a Statement in JavaScript ? JavaScript is a dynamic programming language that allows developers to write complex code with ease. One of the fundamental concepts in JavaScript is the use of operators, which are symbols that perform operations on one or more values. One such operator is the || (logical OR) operator, which can be 6 min read How to convert NaN to 0 using JavaScript ? NaN (Not a Number) is usually used to indicate an error condition for a function that should return a valid number but it can be converted to 0 using JavaScript. We will discuss how to convert the NaN to 0. Below are the approaches used to convert NaN to 0 using JavaScript: Table of Content Using is 3 min read How to get the first non-null/undefined argument in JavaScript ? There are many occasions when we get to find out the first non-null or non-undefined argument passed to a function. This is known as coalescing. Approach 1: We can implement coalescing in pre-ES6 JavaScript by looping through the arguments and checking which of the arguments is equal to NULL. We the 5 min read Like