安装指定版本的nodejs,解决Block-scoped declarations (let, const, function, class) not yet supported outside报错

今天在学习ES6 let命令时,报错Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at 在网上寻找错误的答案,发现是nodejs版本太低的问题。

首先 node -v 查看当前版本,如果当前版本不合适可以安装指定版本的nodejs

升级之前需要安装n模块,sudo npm install -g n

安装n模块后,n -V查看版本

最后升级指定版本的nodejs,sudo n v14.2.0 (我安装的是当前最新版本)

https://nodejs.org/en/这是nodejs的官网,可下载或查看最新版本

安装指定版本的nodejs,解决Block-scoped declarations (let, const, function, class) not yet supported outside报错
用node -v查看版本,v14.2.0`