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

175
Vistas
What would be the purpose of if (thisValue.getTime() === thisValue.getTime())

I have inherited a web project in PHP and of course JS. What purpose would this code below serve in JavaScript? Seems that the 'if' would always be true and the else will never execute. The developer who wrote this is no longer accessible to be asked what he intended by this.

var thisValue = new Date($(this).val());
if (thisValue.getTime() === thisValue.getTime()){
  //some code
}else{
  //some code
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

getTime() should always be equal to itself if the new Date(unknown) is an actual date.

This looks like a hack for the scenario where val in new Date(val) is not a date, in this scenario getTime() should return NaN which is not equal to itself as it doesn't exist.

Compiled output:

if (thisValue.getTime() (number or NaN) === (number or NaN)) {

} else (NaN is not equal to NaN) {

}

Instead of making a weird looking hack, this is cleaner and more readable:

if (!Number.isNaN(thisValue.getTime()) {} else {}
about 4 years ago · Juan Pablo Isaza 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