Questions tagged [automatic-semicolon-insertion]
32 questions
594
votes
7 answers
What are the rules for JavaScript's automatic semicolon insertion (ASI)?
Well, first I should probably ask if this is browser dependent.
I've read that if an invalid token is found, but the section of code is valid until that invalid token, a semicolon is inserted before the token if it is preceded by a line…

T.R.
- 7,442
- 6
- 30
- 34
16
votes
3 answers
Automatic semicolon insertion & return statements
As you might know, ECMAscript tries to be smart and will automatically insert semicolons if you didn't write those explicitly. Simple example
function foo() {
var bar = 5
return bar
}
will still work as expected. But there are some caveats…

jAndy
- 231,737
- 57
- 305
- 359
13
votes
4 answers
No semicolon before [] is causing error in JavaScript
var a = [1, 2, 3, 4];
var b = [10, 20, 30, 40];
console.log([a, b].length)
[a, b].some(function(x) {
x.push(x.shift())
});
I was extremely surprised today when this code caused
[a,b].some(function(x){ x.push(x.shift()) });
…

exebook
- 32,014
- 33
- 141
- 226
7
votes
3 answers
How to add semicolons to Dart code on save automatically?
I am coming from languages that don't use semicolons by default and I keep forgetting adding them all the time. Also it's annoying to type ; all the time.
Is there any VS Code plugin that will add semicolons on save automatically?
If it's not…

kipkipe
- 121
- 2
- 4
4
votes
1 answer
Automatic Semicolon Insertion in JavaScript without parsing
I'm writing a JavaScript preprocessor which automatically inserts semicolons in places where it's necessary. Don't ask why.
Now I know that the general way to tackle this problem is to write a JavaScript parser and add semicolons where necessary…

Aadit M Shah
- 72,912
- 30
- 168
- 299
3
votes
1 answer
Javascript automatic semicolon insertion for do-while statements
Since ES6, a new case has been added for rule 1 of automatic semicolon insertion:
The previous token is ) and the inserted semicolon would then be
parsed as the terminating semicolon of a do-while statement (13.7.2).
This allows one to avoid…

lledr
- 537
- 1
- 3
- 12
3
votes
4 answers
Why do some programming languages allow semicolons to be automatically included?
Languages such as C++ will not work if semicolons are forgotten but other languages such as JavaScript will automatically include them for you.
I know from this article Do you recommend using semicolons after every statement in JavaScript?, that it…

mojo1mojo2
- 1,062
- 1
- 18
- 28
3
votes
1 answer
Does automatic semi-colon insertion in JS affect for loops with the first { on a new line?
Will JS auto semi-colon insertion place a semi-colon at the end of for(...) like I've placed in the following example or is it safe to break the bracket onto a new line with for loops?
for(...);
{
...
}
I've found plenty of info saying what is…

Adrian Payne
- 165
- 2
- 12
2
votes
0 answers
How can I automatically insert semicolons at every optional location while typing?
Summary
I recently discovered that VSCode has this remarkable feature that allows you to define fine-tuned automatic white-space and optional character handling behaviors which are applied to your code in real time as you type.
This is what my life…

Musixauce3000
- 549
- 1
- 3
- 11
2
votes
2 answers
Is there a special character to prevent ASI
When writing Javascript without semicolons, \n becomes the idiomatic statement terminator, but sometimes it is actually not, which I would like to express in my code. So is there a special character that explicitly prevents Automatic Semicolon…

Isabaellchen
- 98
- 10
2
votes
2 answers
How do I enable unnecessary semicolon warnings in JSHint?
Right now if I have:
console.log;
I don't get a warning from JSHint. I'd like to start using the standard of not using semicolons unnecessarily, and I'd appreciate a little help from JSHint. Is there a supported way to enable warnings for…

Citizen
- 12,430
- 26
- 76
- 117
1
vote
1 answer
JetBrains IDEs: How to add semicolon automatically?
Is there a way to add semicolons automatically when inserting a function in JetBrains IDEs? such as Android Studio and IntelliJ IDEA etc.
(in the example here I am using Flutter in Android Studio)
When I press Enter it adds the function, but the…

Yahia
- 31
- 4
1
vote
1 answer
Why does a multiline comment cause automatic semicolon insertion?
I was very surprised by the following behavior
f1 = (x) => {
return /* Comment on x. */ x
}
f2 = (x) => {
return /*
Comment on x.
*/ x
}
console.log(f1(1)) // => 1
console.log(f2(2)) // => undefined
This is clearly…

akim
- 8,255
- 3
- 44
- 60
1
vote
2 answers
Why VScode creating new line on entering each character?
While typing each character, vscode puts a semicolon and move to the next line.
Here I used to type 'import' but it appears as ' i; m; p; o; r; t; '.
How can I solve this problem?
This is how the characters appear on vscode

Sarin M
- 45
- 5
1
vote
3 answers
Convert comma to semi-colon for the certain part of the string using PHP
I have a string which is such like,
$input = "div-item-2,4,maintype:social| heading:sdfsdf| social: 1, 2, 3 | table:Social| item:3| align:vertical| style:icon| isactive:1,8,0";
I would like to convert comma to semi-colon between | is start and end.…

Optimus Prime
- 308
- 6
- 22