?? Operator in TypeScript

"Nullish Coalescing"

If the left operand is null or undefined, 
the ?? expression evaluates to the right operand:

null ?? "n/a"
// "n/a"

undefined ?? "n/a"
// "n/a"

Otherwise, the ?? expression evaluates to the left operand:

false ?? true
// false

0 ?? 100
// 0

"" ?? "n/a"
// ""

NaN ?? 0
// NaN

Notice that all left operands above are falsy values.
If we had used the || operator instead of the ?? operator, 
all of these expressions would've evaluated to their 
respective right operands:

false || true
// true

0 || 100
// 100

"" || "n/a"
// "n/a"

NaN || 0
// 0

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
typescript {} operator typescript operator is ? ? operator typescript !. typescript operator typescript ...operator typescript '!!' operator typescript <> operator and operator typescript typescript | operator operator ! in typescript operators in typescrippt & operator in typescript ?. typescript operator | operator typescript | operator in typescript !! operator in typescript ... operator typescript " | " operator typescript in types " | " operator typescript "|" operator typescript | operator in type definition typescript typescript operator '?' operator & typescript typescript operator !! typescript !: operator in typescript operator ?. operator in typescript type of operator in typescript .? operator typescript "&" operator typescript & operator typescript explain the purpose of the ‘in’ operator in typescript ** operator typescript What is the purpose of the ‘?’ operator in TypeScript typescript ??= operator typescript operator !: ;; operator typescript += operator typescript the in operator in typescript typescript + operator operators in typescript ... operator in typescript typescript ?: operator typescript with operator new typescript operators ?? operator typescript ! typescript ${} operator : operator in typescript operator ?. in typescript typescript operator ? typescript "..." operator and operator in typescript operator "?." typescript ?? operators in ts operator ?? typescript operators typescript typescript || operator typescript ?! operator in typescript ! operator in operator typescript type operator typescript typescript "! operator" typescript $ operator . typescript operator ! operator typescript typescript ?.operator !! typescript operator ! operator in typescript typescript "?." operator operator ? typescript ? operator typescript ... typescript operator typescript operator || typescript operator ?? typescript operator "..." typescript operator ... "?:" typescript operator typescript Option.of typescript operator !! operator !. typescript operator in typescript typescript check member status typescript ! operator ? operator in typescript typescript operator in function typescript ? opartor .? operator in typescript === in typescript ?: in typescript typescript operator !! TYPESCRIPT !! OPERATOR typescript ?. operator operator function typescript operator | typescript typescript in operator typescript in operator list and value "!!" operator typescript !! operator typescript typescript & operator typescript . operator typescript !! operator typescript ?? operator typescript {...} operator typescript ... operator typescript .? operator typescript ? operator typescript operators typescript nullish coalescing else ?? operator typescript operator typescript ?: Operator in TypeScript ?? Operator in TypeScript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source