Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let章节的两个细节 #108

Closed
sapjax opened this issue Dec 30, 2015 · 1 comment
Closed

let章节的两个细节 #108

sapjax opened this issue Dec 30, 2015 · 1 comment

Comments

@sapjax
Copy link

sapjax commented Dec 30, 2015

  • 不存在变量提升 这一节结尾对typeof的解释可能引起歧义,这里typeof x 报错的原因并不是不存在变量提升和**x还没有声明**,而是因为下面的let x导致的暂时性死区。单独一句typeof x并不会报错,关于typeof的这一段移到下一节比较好。

  • const命令 中的这一段:

    const foo;
    // SyntaxError: missing = in const declaration

    上面代码表示,对于const来说,只声明不赋值,就会报错。

    const不赋值的话,只有在严格模式下才会报错。

    另外下面的:

    ```javascript
    const foo = Object.freeze({});
    foo.prop = 123; // 不起作用
    ```
    上面代码中,常量foo指向一个冻结的对象,所以添加新属性不起作用。
    

    给冻结对象添加属性,在常规模式下是不起作用,在严格模式下则会报错。
    结合这两段代码示例,前者运行在严格模式,后者运行在常规模式,而不同摸下的结果都不同,我觉得全书的示例最好统一到一个模式下,或者单独标明是哪种模式。

@ruanyf
Copy link
Owner

ruanyf commented Dec 30, 2015

谢谢指出,说得很正确,我已经改过来了。

@ruanyf ruanyf closed this as completed Dec 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants