A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/null below:

null - JavaScript | MDN

null

Baseline Widely available

null 值特指未不存在任何对象值。它是 JavaScript 的原始值之一,且在布尔运算中被视为假值。

尝试一下
function getVowels(str) {
  const m = str.match(/[aeiou]/gi);
  if (m === null) {
    return 0;
  }
  return m.length;
}

console.log(getVowels("sky"));
// Expected output: 0
语法 描述

值 null 被写作字面量:null。不像 undefined,null 不是全局对象的属性。相反,null 是表示缺少的标识,指示变量未指向任何对象。在 API 中,null 常在预期的值应是一个对象,但又没有关联的对象的地方使用。

// foo 不存在。它从未被定义或初始化:
foo; //ReferenceError: foo is not defined
// 已知 foo 现在已经存在,但它没有类型和值:
const foo = null;
foo; //null
示例 null 与 undefined 的不同点

当检查值是否为 null 或 undefined 时,请注意相等(==)与全等(===)运算符的区别,前者会执行类型转换:

typeof null; // "object"(因历史原因而不是 "null")
typeof undefined; // "undefined"
null === undefined; // false
null == undefined; // true
null === null; // true
null == null; // true
!null; // true
Number.isNaN(1 + null); // false
Number.isNaN(1 + undefined); // true
规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4