是以往任何时候都需要在一个函数定义的末尾添加分号像下面是在JavaScript函数的声明永远需要
function helloWorld() {
//some code
}; //note the semicolon here at the end is it ever necessary? Ever
我有发誓这是可选的朋友分号。我认为它从来不是可选的我从来没有读过关于它在函数结束时是可选的。我从来没有见过任何人做过“除他之外”。分号是可选的。
var hellWorld = function(){
}; // the semicolon here it is optional because you are defining a variable this is OK and optional
而你的朋友会* * *。这是可选的。尤其是在函数声明之后。 – techfoobar 2013-03-01 18:20:15
它不仅是可选的,而且它也是AFAIK“不推荐”(JS中的大多数分号是可选的,但是仍然推荐使用它们)。 – Jon 2013-03-01 18:20:21
在JS中,分号几乎在任何地方都是可选的,因为它不用分号(虽然它可能不是一个好主意,取决于你问的对象)。 – delnan 2013-03-01 18:20:45