I have a script which is meant to distinguish date, number and string formats. When i wanted to check if a user input is date or not, i have faced a rare case in the program.
What i did to check, if user given string can be converted to date, was a simple condition though.
if(!(new Date(userInputValue)=='Invalid Date'));
{ userInputValue = new Date(userInputValue); }
Let's say, if user gives an input as 'JS 53'
The code new Date('JS 53')
converts the string input to Thu Jan 01 1953 00:00:00 GMT+0100 (Central European Standard Time)
If user gives an input as '53 JS'
The code new Date('53 JS')
gives Invalid Date
which is what i expected. Why placement of numbers and strings in a whole string makes a difference ?