在ES6中使用分号 [英] Use of semicolons in ES6

查看:194
本文介绍了在ES6中使用分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的印象是分号已经过时了ES6。但是,我今天遇到了这个:

I was under the impression semicolons became obsolete with ES6. However, I came across this today:

不起作用:

let i = 0

[0, 1, 2, 3, 4, 5, 6].forEach(item => console.log(item))

作品:

let i = 0;

[0, 1, 2, 3, 4, 5, 6].forEach(item => console.log(item))

为什么这里需要分号,我应该何时使用它们?

Why is the semicolon necessary here, and when should I use them?

推荐答案

没有分号[1,2,3,4,5,6]将被评估为属性访问。哪个是完美的JS,我个人不认为添加分号是如此重要,所以我继续使用它们。

Without the semicolon [1,2,3,4,5,6] will be evaluated as property access. Which is perfectly fine JS, I personally don't think that adding semicolons is such a big deal so I keep using them.

这篇关于在ES6中使用分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆