JavaScript权威指南笔记 - Jiajun的编程随想

首页

/

友情链接

/

我的Github

/

关于我


JavaScript权威指南笔记

.. code:: python

>>> def foo():
...   print(a)
...   a = 1
...
>>> foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
    File "<stdin>", line 3, in foo
UnboundLocalError: local variable 'a' referenced before assignment

.. code:: javascript

> function foo() {
    ...   console.log(x);
    ...   var x = 1;
    ...   console.log(x);
    ...
}
>
> foo()
undefined
1

.. code:: javascript

> 1 in [1]
false
> 1 in [1,2]
true
> "0" in [1]
true
> "0" in [1, 2]

原因在于,JS把前面转成索引。。。