Home > Article > Web Front-end > What is the difference between semicolon and comma in javascript
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.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
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 ('x' + 'y').toString()
Just add a semicolon in front of ('x' 'y').toString().
//代码块A var a = 10; var b = 5; var c = a + b //代码块B ;('x' + 'y').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!