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

212
Views
Logical and (&&) type of operator only for null types in Javascript

The logical && operator returns the left side iff it is evaluated as 'falsy'.

null && 10 
> null
0 && 10  
> 0
1 && 10 
> 10 

The nullish coalescing operator (??) returns the left side iff it is not null or undefined.

null ?? 10
> 10
0 ?? 10
> 0
1 ?? 10
> 1

Is there any neat expression to return the left side iff it is null or undefined? Basically, this would be && only for null or undefined and would look like this:

null xx 10
> null
0 xx 10
> 10
1 xx 10
> 10

I need to do the following quite often when parsing default values and it becomes a little tedious to read when someVar gets chained and parse contains more than one function.

defaults?.someVar != null ? parse(defaults.someVar) : null
about 4 years ago · Juan Pablo Isaza
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!