When should I use a semicolon after curly braces in JavaScript?


In JavaScript, Semicolons are optional. Simple statements in JavaScript are generally followed by a semicolon character, just as they are in C, C++, and Java. JavaScript, however, allows you to omit this semicolon if each of your statements is placed on a separate line. It is a good programming practice to use semicolons.

In JavaScript, use a semi-colon after a statement. Let’s see an example of a variable assignment:

var s = function() {
   alert("Hello World!");
};

However, semicolons aren’t necessary for the following function declarations:

function() {
   alert("Hello World!");
};

Updated on: 12-Sep-2019

286 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements