JavaScript Nullish Coalescing(??) Operator Last Updated : 10 Jun, 2024 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 Comment More infoAdvertise with us Next Article JavaScript Nullish Coalescing(??) Operator K Kriyszig Follow Improve Article Tags : JavaScript Web Technologies Node.js 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 Nullish Coalescing Operator (??) in TypeScript The nullish coalescing (??) operator is a logical operator in TypeScript that returns its right-hand side operand if the left-hand side operand is null or undefined; otherwise, it returns the left-hand side operand. This operator is useful for assigning default values to variables, ensuring more con 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 is the use of Null Coalesce Operator ? PHP 7 introduced a null-coalescing operator with ?? syntax. This operator returns its first operand if its value has been set and it is not NULL, otherwise it will return its second operand. This operator can be used in a scenario where the programmer wants to get some input from the user and if the 2 min read Like