javascript - Use of future reserved word in strict mode - Stack Overflow

I am trying to define an array on es6 and I am getting Use of future reserved word in strict mode. This

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 }.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742282269a4414706.html

相关推荐

  • javascript - Use of future reserved word in strict mode - Stack Overflow

    I am trying to define an array on es6 and I am getting Use of future reserved word in strict mode. This

    21小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信