Skip to content

Latest commit

 

History

History
34 lines (21 loc) · 877 Bytes

is-nil.md

File metadata and controls

34 lines (21 loc) · 877 Bytes
标题 标签
isNil(是否 null 或者 undefined) type(类型)

检查指定的值是否为空或未定义。

  • 使用严格相等运算符检查 val 的值是否等于 null 或 undefined。
const isNil = val => val === undefined || val === null;

ts 代码如下:

调用方式:

isNil(null); // true
isNil(undefined); // true
isNil(''); // false

应用场景

以下是一个实战示例:

结果如下:

<iframe src="codes/javascript/html/is-nil.html"></iframe>