EN
JavaScript - when to put semicolon after function definition
3
points
In this article, we would like to show you when to put a semicolon after a function in JavaScript.
Rule:
Semicolons are used to separate statements.
Â
Hints:
1. Semicolons aren't necessary after function declarations (since they are not statements).
function myFunction() {
// ...
}
Â
2. It is recommended to use semicolons after:
a) function expressions, because not using them may lead to bugs.
| Old JS | ES6+ |
|
|
|
|
b) functions created with new operator, because not using them may lead to bugs.
var myFunction = new Function('/* ... */'); /* <---- Semicolon is recommended */
Â