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
🌐
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 ? after the email to pre-check.
🌐
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 - Using TypeScript, 3 places where the exclamation mark operator appears. // ! 就是将之后的结果取反,比如: // 当 isNumber(input) 为 True 时返回 False; isNumber(input) 为 False 时返回True const a = !isNumber(input); The language feature is called Non-null assertion operator. when you add an exclamation mark after variable/property name, you’re telling to TypeScript that you’re certain that value is not null or undefined.
🌐
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.
🌐
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.
🌐
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.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Graphite
graphite.com › guides › typescript-operators
Operators in TypeScript
This operator is generally recommended for use over == in TypeScript (and JavaScript) to avoid errors related to type coercion. === and !== check both value and type, which leads to more predictable and safer code, whereas == and != only check the value after performing type coercion, which can introduce subtle bugs. Logical operators are used to determine the logic between variables or values:
🌐
GitConnected
levelup.gitconnected.com › when-to-use-the-question-mark-or-undefined-type-in-typescript-233e74ab436
When to use the question mark or undefined type in TypeScript | by Ian Spryn | Level Up Coding
January 17, 2023 - So what’s the difference? Simply put, the question mark means the attribute is optional. If you do not provide a value for the attribute, it will be undefined.
🌐
freeCodeCamp
freecodecamp.org › news › how-the-question-mark-works-in-javascript
How the Question Mark (?) Operator Works in JavaScript
February 3, 2021 - 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.
Find elsewhere
🌐
Becomebetterprogrammer
becomebetterprogrammer.com › typescript-question-mark
Understanding the Question Mark (?:) in TypeScript - Become A Better Programmer
April 25, 2022 - This is a big benefit in TypeScript when compared to defining functions in JavaScript as all of the parameters in JavaScript are optional, even if the logic inside the function requires them, while in TypeScript you have to explicitly add the question mark ?: to make parameters optional.
🌐
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 - When we use the double question mark operator (??) to assign a default value to displayName, it checks if name is null or undefined. Since name is null, the default value “Guest” is assigned to displayName.
🌐
Delft Stack
delftstack.com › home › howto › typescript › question mark in typescript
Question Mark Operator in TypeScript | Delft Stack
January 30, 2023 - The question mark or ? has relieved the users by defining optional parameters. Moreover, the ? operator can also act as a shorthand for checking if a certain attribute of an object is null or undefined.
🌐
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.
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";
🌐
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 ...
🌐
Omarileon
omarileon.me › blog › typescript-double-question-mark
mari. | Demystifying TypeScript's Double Question Mark: Nullish Coalescing
January 25, 2024 - If you're running this imaginary ... variables altogether, unless you want to override them. This is where the nullish coalescing operator, those two question marks you've been seeing in TypeScript, come in hand...
🌐
Tim Mousk
timmousk.com › blog › typescript-double-question-mark
How To Use The Double Question Mark Operator In TypeScript? – Tim Mouskhelichvili
March 6, 2023 - The double question mark operator or nullish coalescing operator helps assign a default value to a null or undefined TypeScript variable.