[英]JS semicolon removes 'Uncaught SyntaxError: Unexpected identifier' error why?
My code is this: 我的代码是这样的:
message.labels.forEach(/…/) container.data.push(message);
It throws Uncaught SyntaxError: Unexpected identifier
When I add a semicolon after the forEach
function it doesn't throw it anymore. 它抛出
Uncaught SyntaxError: Unexpected identifier
当我在forEach
函数后添加分号时,它不再抛出。 I only change the semicolon there, I checked it with my git. 我只在那里更改分号,我用git检查了它。
Why does it do it? 为什么这样做呢? Feels like I'm missing some JS fundamentals here.
感觉就像我在这里缺少一些JS基础知识。
The semi-colon ends a statement . 分号结束一个声明 。
If you leave it out, then your two statements are treated as a single one, it doesn't make any sense and the compiler throw an error. 如果不加说明,则将您的两个语句视为一个语句,这没有任何意义,并且编译器将引发错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.