Use of Semicolons After Functions 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: 2019-09-12T07:35:58+05:30

188 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements