JS data types include String, Number, Boolean, Undefined Undefined, Null, and complex Object types.

The Number type has a special value NaN that means Not a Number (Not a numeric value) but is itself a Number. When a string is cast to a numeric type, the string must be purely numeric to cast otherwise NaN will be displayed. For example,

var str = "23" ; var n=Number(str); The string STR is converted to the value 23, and if STR is changed to "a23", console.log(STR) displays NaN.Copy the code

Another conversion method uses parseInt(); Converts a string to an integer from the first digit to a non-numeric position,

var str = "124Fx"; var n =parseInt(str);
Copy the code

ParseInt () can also take a second argument, for example

parseInt(str , 16) 
Copy the code

The second parameter indicates the number of digits to be converted. 16 indicates that STR is converted to hexadecimal, and then STR will be converted to F until the conversion stops. The second parameter is not required

There is also a toFixed() method whose default parameter is 0. The allowed parameter value is 0-20, indicating the number of decimal points to be reserved. When saving trees, it will be automatically rounded, but note that the number of negative numbers will be smaller, which is a small bug

For example, var n= -345.456; var s=n.toFixed(2)Copy the code

The final result will be s=-345.46; ,

ES6 const constants are best named in all uppercase letters with underscores to distinguish words such as

const COL_NUM = 10;
Copy the code

If the object is copied as a constant, it will not be able to clear the object constant from memory, and will become a memory leak. Although the current computer development of a little memory leak will not cause a big impact, or should pay attention to avoid unexpected events