1

I ran into an interesting case with Date.parse is returning a valid date instead of NaN as I would think is expected.

So Date.parse('test 123') returns -58285678164000 and Date.parse('123 test') returns NaN like I would think.

Can anybody explain to me why 'test 123' returns a negative number and '123 test' returns NaN, trying to see how I can check if a string is a date using !isNaN(Date.parse(string)) but this case if giving me an issue.. and I'm just curious on why.

Shawn
  • 2,355
  • 14
  • 48
  • 98
  • 1
    What browser? First one returns NaN in Firefox – charlietfl Jul 16 '19 at 20:57
  • If the string doesn't conform to the standard date specification, the results are implementation-dependent. It's treating the first string as `123-01-01`. – Barmar Jul 16 '19 at 20:59
  • @charlietfl nice, I didn't even try it in Firefox, apparently it returns NaN in Firefox and Edge, but the issue I am seeing is in Chrome – Shawn Jul 16 '19 at 21:16

0 Answers0