It's called the Short-circuit evaluation and it's a feature of TypeScript. Not JavaScript .

When whatever before ? Is null or undefined, whatever after ?. Won't be called. That's to avoid errors like: undefined has no property removeEventListener

Edit

I was wrong when I said it's not a feature of JavaScript. It's actually a new feature. Some browsers that are not updated to the latest don't support it yet (like mine)

Answer from TSR on Stack Overflow
🌐
freeCodeCamp
freecodecamp.org › news › how-the-question-mark-works-in-javascript
How the Question Mark (?) Operator Works in JavaScript
February 3, 2021 - By Nishant Kumar The conditional or question mark operator, represented by a ?, is one of the most powerful features in JavaScript. The ? operator is used in conditional statements, and when paired with a :, can function as a compact alternative ...
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-question-mark-operator
JavaScript Question Mark (?) Operator Explained | Built In
The question mark operator ? takes three operands: a condition, a value if that condition is true and a value if that condition is false. It’s used in JavaScript to shorten an if else statement to one line of code.
Published   July 17, 2025
People also ask

When should I use the ternary operator in JavaScript?
Use the ternary operator when assigning a value based on a simple condition. It helps keep code concise and readable in those scenarios.
🌐
builtin.com
builtin.com › software-engineering-perspectives › javascript-question-mark-operator
JavaScript Question Mark (?) Operator Explained | Built In
What is the syntax of the ternary operator in JavaScript?
The syntax is: condition ? valueIfTrue : valueIfFalse. For example: (1 + 1 == 2) ? "Pass" : "Fail".
🌐
builtin.com
builtin.com › software-engineering-perspectives › javascript-question-mark-operator
JavaScript Question Mark (?) Operator Explained | Built In
Why is it called the ternary operator?
It’s called the ternary operator because it takes three operands: a condition, a result if the condition is true, and a result if the condition is false.
🌐
builtin.com
builtin.com › software-engineering-perspectives › javascript-question-mark-operator
JavaScript Question Mark (?) Operator Explained | Built In
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Conditional_operator
Conditional (ternary) operator - JavaScript | MDN
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:), and finally the expression to execute if the condition is falsy.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Optional_chaining
Optional chaining (?.) - JavaScript | MDN
The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.
🌐
Eran Stiller
eranstiller.com › javascript-double-question-marks
What Is the JavaScript Double Question Marks (??) Operator?
September 24, 2023 - The double question marks operator offers a reliable, concise way to set default values and avoid errors in your code. Remember, it’s all about preventing those pesky null or undefined values from causing havoc in your JavaScript programs.
🌐
Flexiple
flexiple.com › javascript › double-question-mark-javascript
The Double Question Mark (??) in JavaScript - Flexiple
The ?? operator in JavaScript is known as the nullish coalescing operator. It returns the right-hand operand when the left-hand operand is either null or undefined. This operator provides a reliable way to specify default values.
Find elsewhere
🌐
CoreUI
coreui.io › blog › what-is-double-question-mark-in-javascript
What is Double Question Mark in JavaScript? · CoreUI
March 12, 2024 - As of its introduction in ECMAScript 2020, the ?? operator is supported in most modern browsers and JavaScript environments, including Node.js versions that are based on newer V8 engines. However, for older environments or browsers that do not support ECMAScript 2020 features, a transpiler like Babel may be required to ensure compatibility. The double question mark operator enriches JavaScript’s syntax by offering a clear and concise way to handle null and undefined values.
🌐
Educative
educative.io › answers › how-the-question-mark-operator-works-in-javascript
How the question mark (?) operator works in JavaScript
In this example, we determine whether a person is an adult based on their age using the ? operator. If the age is greater than 18, isAdult will be assigned the value Yes; otherwise, it will be assigned No. The question mark operator can also be used inside a function call to make decisions based on the parameters passed in the function.
🌐
Codedamn
codedamn.com › news › javascript
What is the Question Mark in JavaScript? Explained with Examples
February 15, 2023 - If it is, we return the string ‘Cheers 🍻’. If not, we return the string ‘Sorry, no drinks for you 🚫’. The question mark symbol is also used in the nullish coalescing operator.
🌐
Robin Wieruch
robinwieruch.de › javascript-variable-question-mark
JavaScript Variable with Question Mark
The question mark in JavaScript is commonly used as conditional operator -- called ternary operator when used with a colon (:) and a question mark (?) -- to assign a variable name conditionally.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Conditional branching: if, '?'
To do that, we can use the if statement and the conditional operator ?, that’s also called a “question mark” operator.
🌐
Kodeclik
kodeclik.com › question-mark-in-javascript
The question mark (?) operator in Javascript
July 15, 2025 - The question mark operator, represented by a ?, is a powerful feature in JavaScript that is used in conditional statements, and when paired with a :, can function as a compact alternative to if...else statements. There are three main uses for the ?
🌐
BetterBugs
betterbugs.io › blog › javascript-double-question-mark-nullish-coalescing-operator
What is JavaScript Double Question Mark (??) or the Nullish Coalescing Operator?
Simply put, the double question mark (??) operator returns the right-hand operand if the left-hand operand evaluates to a nullish value (either null or undefined).
🌐
Scaler
scaler.com › topics › javascript-nullish-coalescing-operator
What is JavaScript double question mark (??) - nullish coalescing operator - Scaler Topics
November 21, 2022 - The Nullish coalescing operator ... question mark is a logical operator that takes two values and returns the right-hand value if the left-hand value is undefined or null, Else returns the left-hand operand....
🌐
Medium
medium.com › totally-typescript › what-does-the-question-mark-dot-mean-in-javascript-or-typescript-9d7d744f6077
What Does the ?. Question Mark Dot Mean in JavaScript or TypeScript? | by Dr. Derek Austin 🥳 | Totally TypeScript | Medium
May 16, 2023 - What Does the ?. Question Mark Dot Mean in JavaScript or TypeScript? Unraveling the mystery of the ?. optional chaining operator with practical examples Introduction: Optional Chaining in JS / TS …
🌐
Altcademy
altcademy.com › blog › what-is-question-mark-in-javascript
What is question mark in JavaScript
September 14, 2023 - The first and perhaps the most common use of the question mark in JavaScript is as a conditional operator, otherwise known as the ternary operator. The word "ternary" comes from Latin and it means "composed of three parts".
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Nullish_coalescing
Nullish coalescing operator (??) - JavaScript | MDN
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.
🌐
Becomebetterprogrammer
becomebetterprogrammer.com › javascript-how-the-question-mark-works
JavaScript | How does the Question Mark(?) Work? (examples) - Become A Better Programmer
July 10, 2022 - The two question mark symbol (??) forms the null coalescing operator. The operator takes two operands on either side. The expression returns the right-hand side operand if the left-hand side operator is null or undefined.