doc: create sections on notes on types
This commit is contained in:
1 parent
949b3cb56f
commit
4da2180c99
1 file changed
+11
@@ -92,3 +92,14 @@ let isValid = true; //没有错误
|
||||
isValid = "hello!";
|
||||
isValid = 1;
|
||||
```
|
||||
## 关于JavaScript中的类型说明
|
||||
在编写JS程序时,您可能会遇到一些由于JS中奇怪的类型行为而导致的无声错误。自动类型转换或强制转换是常见的、通常令人费解的JS bug来源(即使是有经验的JS程序员)
|
||||
为什么意识到这一点很重要?你将编写使用变量和条件逻辑的程序。知道什么被认为是真/假以及类型是如何被评估的(在高层次上)可以让你成为一个更快乐的JS开发人员([一些实践](https://www.codestepbystep.com/problem/view/javascript/expressions/expressions3))
|
||||
一些“不那么明显”的例子:
|
||||
```javascript
|
||||
2 < 1 < 2;// true
|
||||
0 + "1" + 2;// "012"
|
||||
[] + [];// ""
|
||||
"1" / null;// Infinity
|
||||
[+!![]]+[[![]+!![]]];// "11"
|
||||
```
|
||||
Reference in new issue
Block a user