admin管理员组文章数量:1332395
I am trying to define an array on es6 and I am getting Use of future reserved word in strict mode
. This is my attempt:
{let colours = ["green","yellow","red"]}
What could be the reason?
I am trying to define an array on es6 and I am getting Use of future reserved word in strict mode
. This is my attempt:
{let colours = ["green","yellow","red"]}
What could be the reason?
Share Improve this question asked Jul 22, 2017 at 2:05 user8292330user8292330 4- Why do you have curly braces around it? – Carcigenicate Commented Jul 22, 2017 at 2:07
- I have curly braces because I am trying to define the array in reactJS file – user8292330 Commented Jul 22, 2017 at 2:08
-
2
You cannot define variables inside
.jsx
expressions. Define your array outside of the return statement and reference it in the expression:let colours = ["green","yellow","red"]
and then later{ colours }
The use oflet
is what is causing that error inside of strict mode. Change it tovar
. Sounds like you're in an es2015 env. Or you could transpile your code with something like babel: babeljs.io – Kyle Richardson Commented Jul 22, 2017 at 2:13 - @Kyle you got the right solution for the problem. Thanks. – user8292330 Commented Jul 22, 2017 at 2:18
1 Answer
Reset to default 5The use of let
is what is causing that error inside of strict mode. Change it to var
. Sounds like you're in an es2015 env. Or you could transpile your code with something like babel.
You also cannot define variables inside .jsx expressions. Define your array outside of the return statement and reference it in the expression: let colours = ["green","yellow","red"]
and then later { colours }
.
本文标签: javascriptUse of future reserved word in strict modeStack Overflow
版权声明:本文标题:javascript - Use of future reserved word in strict mode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742282268a2446311.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论