Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Null coalescing operator angular 2

What is the equivalent of null coalescing operator (??) in angular 2?

In C# we can perform this operation:

string str = name ?? FirstName ?? "First Name is null";
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Coalescing is performed via || operator, i.e.

let str:string = name || FirstName || "name is null and FirstName is null";

You can also read this question for more details and explanations.

about 4 years ago · Santiago Trujillo Report

0

In Typescript

Typescript introduced null coalescing with version 3.7, so if you're running on 3.7 or higher you can simply write:

const str = name ?? firstName ?? "Name and First Name are both null";
const x = foo?.bar.baz() ?? bizz();

See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing.

In the Angular Template

Since Angular 12 you can also use ?? in the template.

about 4 years ago · Santiago Trujillo Report

0

Maybe what you want achieve is this:

let str =
    typeof (name) !== 'undefined' && name !== null ?
        name : typeof (FirstName ) === 'undefined' || FirstName  === null ?
        "First Name is null" : FirstName 
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!