Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

what is diffrents between:

var functionName = function() {}

and

function functionName() {}

in javascript
Posted

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:


JavaScript
f1();
f2();

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

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.

 
Share this answer
 
JavaScript
var functionName = function() {}


This function returns value and set in to variable

JavaScript
function functionName() {}


It executes code.. :)

for more information.. :)

Functions and function scope[^]

Functions: declarations and expressions[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900