Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda