定义函数的JavaScript差异 [英] JavaScript differences defining a function
本文介绍了定义函数的JavaScript差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚购买了最新版本的JavaScript:The Definitive Guide,并且已经有了一个问题。 :D
I just bought the newest version of "JavaScript: The Definitive Guide" and already have a question. :D
下列行在语义上是否相同:
Are the following lines semantically the same:
var square = function(n){
return n * n;
};
和
function square(n){
return n * n;
}
如果是,使用其中任何一个有什么优点/缺点?
If yes, what are the advantages/disadvantages of using either of them?
感谢您的帮助!
推荐答案
检查出来:
a(); // prints 'A'
function a(){
console.log('A');
};
这个:
b(); // throws error. b is not a function
var b = function() {
console.log('B');
};
您是否注意到差异?
这篇关于定义函数的JavaScript差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文