当前位置:网站首页>JS cast

JS cast

2022-06-26 17:55:00 Dandan's servant

  1. Numbers and other types of data When comparing , Will convert other types of data into numbers for comparison ( Some data types , For example, the array will first use toString Convert to string , Finally, it is converted into numbers ).

  2. Boolean values and other data types When comparing , Will preferentially convert Boolean values to numbers , Then convert other data types to numbers for comparison , That is, the operation of the previous rule .

  3. undefined Except for and null Perform an incomplete comparison and return true, All others are returned false.null Except for and undefined Perform an incomplete comparison and return true, All others are returned false.

  4. Array ( Or object ) And string When comparing , Array ( Or object ) Will be converted to a string for comparison .

  5. Use Boolean() When converting , If omitted or value 0,-0,null,false,NaN,undefined, Or empty string (""), The object has an initial value of false. All other values , Including any object , An empty array ([]) Or a string "false", Will create an initial value of true The object of .

原网站

版权声明
本文为[Dandan's servant]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261723036897.html