When I declared a js function, and added a semicolon at the end, which is: function foo(){};
Then jshint prompted unnecessary semicolon . Why?
A function (or class) declaration is a complete statement; it should not have a semicolon.
You only need a semicolon for regular executable statements (including const x = function() { ... };
).
there are 2 types of function writting
see the below example
function _functionName() {
}; // this is not required
var _functionName = function() {
}; //this is okey
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.