When reading others code I have seen functions written both ending with a semi-colon and not ending with a semi-colon.
with:
var testFunction = function() {
// magic happens here
};
without:
var testFunction = function() {
// magic happens here
}
Update: I also found this very useful => https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope
Semicolons after function declarations are not necessary. There's no semicolon grammatically required, but might wonder why? Semicolons serve to separate statements from each other, and a FunctionDeclaration is not a statement.
The main difference between a function expression and a function declaration is the function name, which can be omitted in function expressions to create anonymous functions. A function expression can be used as an IIFE (Immediately Invoked Function Expression) which runs as soon as it is defined.
Function expressions are when you create a function and assign it to a variable. The function is anonymous, which means it doesn't have a name. For example: let myFunction = function() { // do something }; As you can see, the function is assigned to the myFunction variable.
It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.
At it's root, what you have there is an assignment statement, and according to the Google Javascript Style Guide, all statements should end in a ;
. Especially assignment statements. JSLint requires ;
or else it won't pass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With