Do I need to use a semicolon after every function in JavaScript?


Commonly, adding semicolons in JavaScript is 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.

No need of a semicolon in a function declaration:

function functionname(s) {
}

If the function is written as a statement, it should have a semicolon like any other statement in JavaScript:

var a = function functionname(s) {
};

Updated on: 12-Sep-2019

129 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements