Reputation: 76
I am using jshint in VSCode. jshint gives a "missing semicolon" warning at the end '}' of the function below
void function doSomething(){
console.log('Hello, World');
}
And adding the semicolon satisfies jshint:
But after I remove void
, the warning goes away without the semicolon:
void function doSomething(){
console.log('Hello, World');
}
What is the logic behind this? More generally, is there official style guidance such as PEP8 in Python for Javascript addressing the best practice for semicolon?
Upvotes: 1
Views: 451
Reputation: 943561
With the linting rules you have:
By putting the void
operator before the function
keyword, you force it into expression context.
Since it is in expression context, you do nothing with the function in the expression, and you void the result, it becomes pointless. The expression doesn't do anything at all. It doesn't even create a variable with the function stored in it, which is why this errors:
void function x() { console.log(1) };
x();
More generally, what's the best practice rule on semicolns in javascript?
A highly opinionated subject.
Upvotes: 2