1.equal
=== 为绝对相等,即数据类型与值都必须相等。
原始值可以使用 JavaScript 的属性和方法,因为 JavaScript 在执行方法和属性时可以把原始值当作对象。用typeof可以获取对应的类型。
2.js数据类型
typeof undefined // undefined
typeof null // object
null === undefined // false
null == undefined // true
typeof "John" // 返回 string
typeof 3.14 // 返回 number
typeof NaN // 返回 number
typeof false // 返回 boolean
typeof [1,2,3,4] // 返回 object
typeof {name:'John', age:34} // 返回 object
typeof new Date() // 返回 object
typeof function () {} // 返回 function
typeof myCar // 返回 undefined (如果 myCar 没有声明)
typeof null // 返回 object
3.boolean
如果布尔对象无初始值或者其值为:0 -0 null "" false undefined NaN 那么对象的值为 false。否则,其值为 true
4. Constructor
<script type="text/javascript"> var test=new Array(); if (test.constructor==Array) { document.write("This is an Array"); } if (test.constructor==Boolean) { document.write("This is a Boolean"); } if (test.constructor==Date) { document.write("This is a Date"); } if (test.constructor==String) { document.write("This is a String"); } </script>
本文详细介绍了JavaScript中的数据类型,包括基本类型如undefined、null、字符串、数字、布尔值等的特点及判断方法,并探讨了类型之间的比较规则。此外,还讨论了如何通过构造函数判断数据类型。

被折叠的 条评论
为什么被折叠?



