What is the difference between: var functionName = function() {} and function functionName() {} in Javascript

JavascriptWeb DevelopmentFront End Technology

functionDisplayOne is a function expression, however, functionDisplayTwo is a function declaration. It is defined as soon as its surrounding function is executed.

Both the ways are used to declare functions in JavaScript and functionDisplayOne is an anonymous function.

Here’s the function expression −

functionDisplayOne();
var functionDisplayOne = function() {
   console.log("Hello!");
};

The following is the function declaration −

functionDisplayTwo();
function functionDisplayTwo() {
   console.log("Hello!");
}
raja
Published on 18-Jan-2018 13:19:04
Advertisements