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

170
Views
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 answers
Answer question

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 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!