当我在 js 中运行一个函数时,它似乎工作正常,但是这样可以吗?
函数 myfunction(){ }
VS
var myfunction = 函数(){ }
因为两者的名称相同,所以没有区别吗? 抱歉,我是 js 新手,所以我只是确保学习这种风格是有好处的。 (第一个功能是我更喜欢使用的。)
最佳答案
这个问题已经在 link 中提出过。 , 基本区别之一来自声明,例如:-
foo();
var foo = function(){
console.log('hi');
}
会导致未定义,因为它是在声明之前调用的,另一方面,
foo();
function foo(){
console.log('hi');
}
would console 'hi' with no problem, for further insight check the above link.
关于Javascript函数有什么区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40054805/