Semicolon Insertion

Semicolon insertion refers to the ability of JavaScript to insert semicolons between statements that are separated by a new line. This feature is something that must be in the back of your mind when working on javascript.

If I write this...

var a = 3
var b = 5

JavaScript will automatically insert the necessary semicolons...

var a = 3;
var b = 5;

However, it is highly recommended that you provide the necessary semicolons yourself. This is because there are cases where the interpreter may make mistakes when inserting the semicolons. An example is...

return
	true;

After Semicolon insertion, that will become...

return;
	true;

You probably wanted return true;.

Related Articles

JavaScript Syntax Rationale
blog comments powered by Disqus