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 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: 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
Add a ment  | 

1 Answer 1

Reset to default 5

The 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