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 }
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742282269a4414706.html
评论列表(0条)