doubleyong
管理员
管理员
  • 最后登录2025-10-08
  • 发帖数1198
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:8838回复:0

let 等es6 命令报错:SyntaxError: Block-scoped declarations (let, const, function, class)

楼主#
更多 发布于:2017-10-18 22:13
使用ES6 新语法,使用let 定义变量,代码如下:

let num = 5;
console.log(num);


运行时,提示如下错误:

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

解决方法就是,在文件头添加”javascript 严格模式”声明:
"use strict";
let num = 5;
console.log(num);


添加严格模式后,代码即可正常运行了
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号