php undefined null,undefined与null有什么区别

编程入门 行业动态 更新时间:2024-10-06 18:25:10

php undefined null,undefined与null<a href=https://www.elefans.com/category/jswz/34/1771105.html style=有什么区别"/>

php undefined null,undefined与null有什么区别

首先我们知道undefined与null都属于 JavaScript 的 7 种基本类型。

(推荐教程:js教程)let primitiveTypes = ['string','number','null','undefined','boolean','symbol', 'bigint'];

它们是属于虚值,可以使用Boolean(value)或!!value将其转换为布尔值时,值为false。console.log(!!null); // false

console.log(!!undefined); // false

console.log(Boolean(null)); // false

console.log(Boolean(undefined)); // false

区别:

undefined是未指定特定值的变量的默认值,或者没有显式返回值的函数,如:console.log(1),还包括对象中不存在的属性,这些 JS 引擎都会为其分配 undefined 值。

null是“不代表任何值的值”。 null是已明确定义给变量的值。 在此示例中,当fs.readFile方法未引发错误时,我们将获得null值。

在比较null和undefined时,我们使用==时得到true,使用===时得到false。console.log(null == undefined); // true

console.log(null === undefined); // false

更多推荐

php undefined null,undefined与null有什么区别

本文发布于:2024-02-27 22:03:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1766365.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   php   undefined   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!