Javascript 未捕获的 SyntaxError:在严格模式之外尚不支持块范围的声明(let、const、function、class)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33001246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 14:29:52  来源:igfitidea点击:

Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

javascript

提问by RogerWang

This error pops up on my JS console in the browser, and I'm not sure how to interpret the message. Can anyone describe what causes this?

浏览器中的 JS 控制台上弹出此错误,我不确定如何解释该消息。谁能描述一下是什么原因造成的?

Thanks

谢谢

回答by Omar Elawady

This means that you must declare strict mode by writing "use strict"at the beginning of the file or the function to use block-scope declarations.

这意味着您必须通过"use strict"在文件或函数的开头写入来声明严格模式以使用块范围声明。

EX:

前任:

function test(){
    "use strict";
    let a = 1;
}