Skip to content

Commit

Permalink
统一引号 (#282)
Browse files Browse the repository at this point in the history
* 统一引号

* 统一引号
  • Loading branch information
Linho1219 authored Sep 24, 2024
1 parent 200b44e commit 1df4272
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/types/null-undefined-boolean.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ undefined == null

既然含义与用法都差不多,为什么要同时设置两个这样的值,这不是无端增加复杂度,令初学者困扰吗?这与历史原因有关。

1995年 JavaScript 诞生时,最初像 Java 一样,只设置了`null`表示"无"。根据 C 语言的传统,`null`可以自动转为`0`
1995年 JavaScript 诞生时,最初像 Java 一样,只设置了`null`表示“无”。根据 C 语言的传统,`null`可以自动转为`0`

```javascript
Number(null) // 0
Expand All @@ -46,7 +46,7 @@ Number(null) // 0

但是,JavaScript 的设计者 Brendan Eich,觉得这样做还不够。首先,第一版的 JavaScript 里面,`null`就像在 Java 里一样,被当成一个对象,Brendan Eich 觉得表示“无”的值最好不是对象。其次,那时的 JavaScript 不包括错误处理机制,Brendan Eich 觉得,如果`null`自动转为0,很不容易发现错误。

因此,他又设计了一个`undefined`。区别是这样的:`null`是一个表示“空”的对象,转为数值时为`0``undefined`是一个表示"此处无定义"的原始值,转为数值时为`NaN`
因此,他又设计了一个`undefined`。区别是这样的:`null`是一个表示“空”的对象,转为数值时为`0``undefined`是一个表示此处无定义的原始值,转为数值时为`NaN`

```javascript
Number(undefined) // NaN
Expand Down

0 comments on commit 1df4272

Please sign in to comment.