Home  >  Article  >  Web Front-end  >  What is the difference between semicolon and comma in javascript

What is the difference between semicolon and comma in javascript

WBOY
WBOYOriginal
2022-03-01 15:10:564782browse

In JavaScript, a semicolon is used to indicate the end of a statement, or to separate three paragraphs in a for statement; and a comma is used to separate two clauses, or to separate parameters in a function definition or call.

What is the difference between semicolon and comma in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What is the difference between semicolon and comma in javascript

In javascript: semicolon generally indicates the end of a statement, or is used to separate three paragraphs in a for statement; comma is generally used to separate the sequence. Two clauses, or arguments separated in a function definition or call.

For example:

var i = 0, j = 2;
for (var k=0 ; k < j; k++) {
i = i + round(4 * (k + 1) * 3.14159, 2);
}

Like many plug-ins, there will be a semicolon in front of the first sentence of js, which is used to avoid that the interpreter may fail when merging the following js files such as the following situation. Something went wrong.

//代码块A
var a = 10;
var b = 5;
var c = a + b
//代码块B
(&#39;x&#39; + &#39;y&#39;).toString()

Just add a semicolon in front of ('x' 'y').toString().

//代码块A
var a = 10;
var b = 5;
var c = a + b
//代码块B
;(&#39;x&#39; + &#39;y&#39;).toString()

So, the semicolon is such an important thing.

Related recommendations: javascript learning tutorial

The above is the detailed content of What is the difference between semicolon and comma in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn