It is to mark the parameter as optional.

  • TypeScript handbook https://www.typescriptlang.org/docs/handbook/2/functions.html#optional-parameters
  • TypeScript Deep Dive https://basarat.gitbook.io/typescript/type-system/functions#optional-parameters
Answer from Fidan Hakaj on Stack Overflow
🌐
Yeminyi
yeminyi.github.io › myblog › typescript › 2020 › 11 › 20 › question-mark-in-typescript.html
Why use Question mark and Exclamation mark in TypeScript | Amy’s blog
November 20, 2020 - Operator and call stack.split when the attribute exists. If stack does not exist, return empty return new Error().stack?.split('\n'); // the same as below const err = new Error(); return err.stack && err.stack.split('\n'); // Before if (foo && foo.bar && foo.bar.baz) { // ... } // After if (foo?.bar?.baz) { // ... } Using TypeScript, 3 places where the exclamation mark operator appears.
🌐
Medium
medium.com › @teamcode20233 › understanding-double-question-mark-operator-in-typescript-be869f210fe6
Understanding Double Question Mark Operator (??) in TypeScript | by Teamcode | Medium
July 3, 2023 - Here’s an example usage of the double question mark operator: const defaultValue = "Default Value"; const value = null; const result = value ?? defaultValue; ... In the above code, value is null, so the double question mark operator returns ...
🌐
Graphite
graphite.com › guides › typescript-operators
Operators in TypeScript
The && operator (logical AND) returns true only if both operands are true; in the example, condition1 && condition2 returns false because condition2 is false. The || operator (logical OR) returns true if at least one of the operands is true, which is why condition1 || condition2 evaluates to true, and the ! operator (logical NOT) inverses the boolean value of its operand, making !condition1 return false since condition1 is true. The ternary operator <condition> ? <output> : <output> in TypeScript is a shorthand for the if-else statement, which is used to assign a value to a variable based on some specified condition.
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-question-mark-dot
What is the ?. operator (optional chaining) in TypeScript | bobbyhadz
The question mark dot (?.) syntax is called optional chaining in TypeScript and is like using dot notation to access a nested property of an object, but instead of causing an error if the reference is nullish, it short-circuits returning undefined.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › typescript tutorial › typescript question mark
TypeScript Question Mark | Complete Guide to TypeScript Question Mark
April 11, 2023 - TypeScript question mark are used on variables to mark it as an optional parameter. When declaring a TypeScript variable, the declared variable becomes an optional parameter. This optional parameter will have undefined if not used. In TypeScript 3.7 version, we have a concept of optional chaining, which lets the user write code where TypeScript can stop running of such expression which return null or undefined.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Delft Stack
delftstack.com › home › howto › typescript › question mark in typescript
Question Mark Operator in TypeScript | Delft Stack
January 30, 2023 - Let’s have another example without the Props interface. ... function getDetails(name :string, age? : number){ if ( age === undefined){ console.log("Name : " + name); } else { console.log("Name : " + name + ", Age : " + age.toString()); } } getDetails("Geralt"); getDetails("Geralt", 95); ... The question mark or ? operator can also be used to check if a certain attribute of an object is null or undefined.
🌐
Educative
educative.io › answers › how-to-use-a-question-mark-in-typescript-variables
How to use a question mark in TypeScript variables
In the following code snippet, we use the toUpperCase method on email that the typescript provides to apply on strings. Now it will raise the error Cannot read property 'toUpperCase' of undefined. The error says that it cannot apply toUpperCase on undefined, since it can only apply this to strings. ... To resolve the error above, use the question mark ?
🌐
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 …
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › how-the-question-mark-works-in-javascript
How the Question Mark (?) Operator Works in JavaScript
February 3, 2021 - But if you use || to provide a default value, you may encounter unexpected behaviors if you consider some values as usable (for example, '' or 0). Consider a scenario where a variable has the value of 0 or an empty string. If we use (||), it will be considered as undefined or NULL and return some default value that we have fixed. Instead of the logical OR (||) operator, you can use double question marks (??), or Nullish Coalescing.
🌐
Gyata
gyata.ai › typescript › typescript-question-mark-operator
TypeScript Question Mark Operator | Gyata - Learn about AI, Education & Technology
It helps us to read the value of properties located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid. let user = {}; // an object console.log(user?.profile?.name); // undefined In this example, trying to access ...
🌐
Becomebetterprogrammer
becomebetterprogrammer.com › typescript-question-mark
Understanding the Question Mark (?:) in TypeScript - Become A Better Programmer
April 25, 2022 - In a similar way, we can do so this when defining a class. class Car { id: string; brand: string; model: string; year: number; price?: number; } This gives the flexibility to not having the need to provide values to all properties of a class.
Top answer
1 of 15
432

Yes. As of TypeScript 3.7 (released on November 5, 2019), this feature is supported and is called Optional Chaining:

At its core, optional chaining lets us write code where TypeScript can immediately stop running some expressions if we run into a null or undefined. The star of the show in optional chaining is the new ?. operator for optional property accesses.

Refer to the TypeScript 3.7 release notes for more details.


Prior to version 3.7, this was not supported in TypeScript, although it was requested as early as Issue #16 on the TypeScript repo (dating back to 2014).

As far as what to call this operator, there doesn't appear to be a consensus. In addition to "optional chaining" (which is also what it's called in JavaScript and Swift), there are a couple of other examples:

  • CoffeeScript refers to it as the existential operator (specifically, the "accessor variant" of the existential operator):

The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties. Use it instead of the dot accessor . in cases where the base value may be null or undefined.

  • C# calls this a null-conditional operator.

a null-conditional operator applies a member access, ?., or element access, ?[], operation to its operand only if that operand evaluates to non-null; otherwise, it returns null.

  • Kotlin refers to it as the safe call operator.

There are probably lots of other examples, too.

2 of 15
157

It is now possible, see answer of user "Donut".

Old answer: Standard JavaScript behaviour regarding boolean operators has something that may help. The boolean methods do not return true or false when comparing objects, but in case of OR the first value that is equal to true.

Not as nice as a single ?, but it works:

var thing = foo && foo.bar || null;

You can use as many && as you like:

var thing = foo && foo.bar && foo.bar.check && foo.bar.check.x || null;

Default values are also possible:

var name = person && person.name || "Unknown user";
🌐
Syncfusion
syncfusion.com › blogs › javascript › use of the exclamation mark in typescript
Use of the Exclamation Mark in TypeScript | Syncfusion Blogs
December 6, 2022 - In the above code example, you can see the use of ? after the parameter. In TypeScript, the question mark is used to define an argument as optional. It is the same as specifying the type as undefined.
🌐
Omarileon
omarileon.me › blog › typescript-double-question-mark
mari. | Demystifying TypeScript's Double Question Mark: Nullish Coalescing
January 25, 2024 - As the name implies, it's nullish coalescing combined with assignment: let var1 = null; var1 ??= 'Replacing null'; var1 ??= 'Wont pick me (var1 isnt null)' In the example above, "var1" ...
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › why-use-question-mark-in-typescript-variable
Why use Question Mark in TypeScript Variable? - GeeksforGeeks
July 12, 2025 - The question mark in TypeScript is used to mark a variable as optional, allowing it to be omitted or set to undefined. This is commonly used in object properties and function parameters, enhancing flexibility by making variables non-mandatory.
🌐
Angular Wiki
angularjswiki.com › angular › double-question-marks-or-nullish-coalescing-operator-in-angular-typescript
Double Question Marks(??) or Nullish coalescing Operator in Angular/Typescript | Angular Wiki
The syntax of nullish coalescing operator is very simple just use double question marks ‘??’ after the variable followed by default value. ... You might be thinking that I will use OR operator ‘||’ to assign default values.
🌐
xjavascript
xjavascript.com › blog › typescript-double-question-mark
Understanding the TypeScript Double Question Mark (`??`) Operator — xjavascript.com
The nullish coalescing operator works well with the optional chaining operator (?.). They can be used together to handle deeply nested optional properties in objects. interface NestedObject { prop1?: { prop2?: { value?: number | null; } | null; } | null; } const nestedObj: NestedObject = {}; const finalValue = nestedObj.prop1?.prop2?.value?? 0; console.log(finalValue); // Output: 0 · The TypeScript double question mark (??) operator, or the nullish coalescing operator, is a powerful tool for handling null and undefined values in a concise and clear way.
🌐
DEV Community
dev.to › danywalls › simplify-your-typescript-code-with-optional-chaining-and-nullish-coalescing-37on
Simplify Your Typescript Code with Optional Chaining and Nullish Coalescing - DEV Community
May 23, 2023 - The double question mark (??) checks if the left-hand side value is nullish (null or undefined) and provides the right-hand side value as the default if needed. Nullish coalescing ensures that we always have a valid jersey number, even if it's missing in the player data. Optional chaining and nullish coalescing are powerful features in TypeScript that greatly enhance data handling in NBA-related projects.