简体   繁体   English

JavaScript 中分号是可选的。 但是,我可以省略 for 循环中的分号吗?

[英]Semicolon is optional in JavaScript. However, could I omit the semicolons in the for loop?

Semicolon is optional in JavaScript. JavaScript 中分号是可选的。 However, could I omit the semicolons in the for loop?但是,我可以省略 for 循环中的分号吗? For example:例如:

for (let i = 0 i < arr.length i++) {
    console.log(arr[i])
}

I'm new to JavaScript, I'm coming from C and C++ where semicolon is a must.我是 JavaScript 的新手,我来自 C 和 C++,其中分号是必须的。

Semicolons are used when you have more than one statements.当您有多个语句时使用分号。 If you have only one statement in for loop, you don't need to put semicolon.如果 for 循环中只有一条语句,则不需要放置分号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript。 循环问题 - JavaScript. Problems with a loop 我可以在所有JavaScript版本中(如果有的话)在行尾省略每个分号吗? - May I omit every semicolon at the end of line in all version (if any) of JavaScript? 异步/等待 for 循环 javascript。 - async/await in for loop javascript. 我的循环在 Javascript 中不起作用。 我必须遍历循环到数组并乘以 2 - Mine loop doesn't work in Javascript. I have to traverse loop to array and multiply by 2 我尝试在 javascript 中创建一个 while 循环。 我有我想在身体上做什么的例子 - I try to make a while loop in javascript. I have example of what i'm trying to do in body JavaScript。 循环遍历 div 的子集 - JavaScript. loop through subsets of divs 我如何不能正确使用分号(javascript)? - How am I not using semicolons properly (javascript)? 我正在尝试用 javascript 编写一个 while 循环。 我的 console.log 没有打印请求的消息 - I am trying to write a while loop in javascript. My console.log does not print the requested message 我需要使用JavaScript循环工作的Google App脚本。 (PDF邮件合并) - I need to loop a working Google App Script, using JavaScript. (PDF Mail Merge) 在IOS5之前,我可以使UIWebView中的PDF使用Javascript滚动。 如何在IOS5下执行此操作? - Before IOS5 I could cause a PDF within a UIWebView to scroll using Javascript. How do I do this under IOS5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM