null值表示故意缺少任何對象值。
它是JavaScript的原始類型之一。
null值不是全局對象屬性的標識符,如undefined。相反,null表示缺少標識,表示變量沒有指向任何對象。
null
var str; if (str == null) { // str is null } else { // str is not null }測試看看?/?
null和undefined的值相等,但類型不同。
在檢查null或undefined時,請注意equals(==)和identity(===)運算符之間的差異,因為前者執(zhí)行類型轉(zhuǎn)換。
typeof null // "object" (由于遺留原因,不是“null”) typeof undefined // "undefined" null == undefined// true null === undefined // false測試看看?/?
所有瀏覽器完全支持null值:
Value | ![]() | ![]() | ![]() | ![]() | ![]() |
null | 是 | 是 | 是 | 是 | 是 |
JavaScript版本: | ECMAScript 1 |
---|
如果給定的字符串不包含[aeiou]字母,則getVowels()函數(shù)將返回0:
function getVowels(str) { var x = str.match(/[aeiou]/gi); if (x === null) { return 0; } return x.length; }測試看看?/?