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

255
Vistas
Does if(this) {} else {} ever visit the else in JavaScript?

Is there any case where the condition if(this) {} fails? Because I couldn't think of a scenario where this is undefined.
This is not an important question nor something anyone would normally use, I'm just asking out of pure curiosity.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Yes, in some execution contexts, this is undefined, which is falsy in JavaScript:

In strict mode, however, if the value of this is not set when entering an execution context, it remains as undefined, as shown in the following example:

Here is at least one convoluted scenario in which the following conditions must be met:

  • global or function execution in strict mode
  • the function was defined at the top-level (effectively being a function of window)
  • that function was called directly without invoking its parent (i.e. foo() and not window.foo())
  • the function returned this
function foo() {
  'use strict'; // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
  return this;
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

over 4 years ago · Santiago Trujillo Denunciar
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