An error with new Date()

 

Javascript is a weakly typed language, which means that a variable does not need to specify a type when declaring a variable, and the variable may not be of the same data type before and after the assignment.

For example: var a = 1; a = '1'; is fine

But remember that values ​​are typed.

When writing the code today, according to the value passed from the background 

Write a line of code value = new Date(value);

The result reports an error invalid date;

The reason is that although this value is a timestamp, the string type is used when it is passed.

new Date requires a variable of type number

You can use the method parseInt() to convert a string type variable to a number type

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326202947&siteId=291194637
Recommended