[英]At end of JS function declaration, adding semicolon, why jshint prompt an error
When I declared a js function, and added a semicolon at the end, which is: function foo(){};
当我声明一个js函数并在末尾添加分号时:
function foo(){};
Then jshint prompted unnecessary semicolon . 然后jshint提示不必要的分号 。 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() { ... };
). 对于常规的可执行语句(包括
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.