本文介绍了函数声明后我们需要一个分号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人在函数声明后添加了分号,但有人没有。这是在函数声明后添加分号的好习惯吗?
Someone added semicolon after function declaration, but someone not. Is this a good practice to add semicolon after function declaration?
function test(o) {
}
function test(o) {
};
推荐答案
函数声明不需要(也不应该有)分号后面的分号:
A function declaration does not need (and should not have) a semicolon following it:
function test(o) {
}
但是,如果将函数编写为语句,就像下面的变量初始化程序一样,然后语句应该用分号终止,就像任何其他语句一样:
However, if you write a function as a statement, like the variable initializer below, then the statement should be terminated with a semicolon, just like any other statement would be:
var a = function test(o) {
};
这篇关于函数声明后我们需要一个分号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!