var functionName = function(){}和function functionName(){}之间的区别是什么 [英] what is diffrents between var functionName = function() {} and function functionName() {}

查看:124
本文介绍了var functionName = function(){}和function functionName(){}之间的区别是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

之间的区别是什么:

var functionName = function(){}



函数functionName(){}

在javascript

hello

what is diffrents between:

var functionName = function() {}

and

function functionName() {}

in javascript

推荐答案

中这两个语句都声明了一个函数对象.在初始化对象这一点上可能有所不同.考虑以下代码:

The both of the statements declares a function object. A difference can be on the point that the object is initialized. Consider the following code:


f1();
f2();

function f1() {}
var f2 = function() {};
var f3 = function() {};

f3();

如果运行上面的代码,您会发现f1的调用是有效的,而f2undefined的调用在我们尝试对其进行调用时(在声明之前)是有效的.对f3的调用是有效的,因为它是在声明之后.

If you run the code above, you will see that the call of f1 is valid while f2 is undefined at the point we try to call it (before its declaration). The call to f3 is valid, since it''s after its declaration.


var functionName = function() {}



此函数返回值并设置为变量



This function returns value and set in to variable

function functionName() {}



它执行代码.. :)

有关更多信息.. :)

函数和函数范围 [函数:声明和表达式 [



It executes code.. :)

for more information.. :)

Functions and function scope[^]

Functions: declarations and expressions[^]


这篇关于var functionName = function(){}和function functionName(){}之间的区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆