如果“else”将要发生,如果它应该宣布或否? [英] If 'else' is about to happen anyway should it be declared or not?
本文介绍了如果“else”将要发生,如果它应该宣布或否?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
应该‘ else’
如果不需要, / p>
When
a = 0
这个:
var foo = function() {
if (a != 0) return true
return false
}
$ b
Or this:
var bar = function() {
if (a != 0) return true
else return false
}
推荐答案
差异。
像往常一样,你可以争论风格。
As usual, you can argue about style. My 50 cents: the first variant (no explicit else) is nicer because it's less code doing exactly the same.
当然,在这种情况下,你会做
Of course, in this case, you would do
return a != 0;
...但我认为这个问题是一般的。
... but I think the question is meant to be general.
这篇关于如果“else”将要发生,如果它应该宣布或否?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文