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

JavascriptWeb DevelopmentFront End Technology

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) {
};
raja
Published on 25-Jan-2018 09:30:02
Advertisements