var functionName = function() {} vs function functionName() {} var functionName = function() {} vs function functionName() {} javascript javascript

var functionName = function() {} vs function functionName() {}


The difference is that functionOne is a function expression and so only defined when that line is reached, whereas functionTwo is a function declaration and is defined as soon as its surrounding function or script is executed (due to hoisting).

For example, a function expression:

// TypeError: functionOne is not a functionfunctionOne();var functionOne = function() {  console.log("Hello!");};