File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ undefined == null
35
35
36
36
既然含义与用法都差不多,为什么要同时设置两个这样的值,这不是无端增加复杂度,令初学者困扰吗?这与历史原因有关。
37
37
38
- 1995年 JavaScript 诞生时,最初像 Java 一样,只设置了` null ` 表示"无" 。根据 C 语言的传统,` null ` 可以自动转为` 0 ` 。
38
+ 1995年 JavaScript 诞生时,最初像 Java 一样,只设置了` null ` 表示“无” 。根据 C 语言的传统,` null ` 可以自动转为` 0 ` 。
39
39
40
40
``` javascript
41
41
Number (null ) // 0
@@ -46,7 +46,7 @@ Number(null) // 0
46
46
47
47
但是,JavaScript 的设计者 Brendan Eich,觉得这样做还不够。首先,第一版的 JavaScript 里面,` null ` 就像在 Java 里一样,被当成一个对象,Brendan Eich 觉得表示“无”的值最好不是对象。其次,那时的 JavaScript 不包括错误处理机制,Brendan Eich 觉得,如果` null ` 自动转为0,很不容易发现错误。
48
48
49
- 因此,他又设计了一个` undefined ` 。区别是这样的:` null ` 是一个表示“空”的对象,转为数值时为` 0 ` ;` undefined ` 是一个表示" 此处无定义" 的原始值,转为数值时为` NaN ` 。
49
+ 因此,他又设计了一个` undefined ` 。区别是这样的:` null ` 是一个表示“空”的对象,转为数值时为` 0 ` ;` undefined ` 是一个表示“ 此处无定义” 的原始值,转为数值时为` NaN ` 。
50
50
51
51
``` javascript
52
52
Number (undefined ) // NaN
You can’t perform that action at this time.
0 commit comments