var functionName = function() {} vs function functionName() {}
@lebyy▲ 0 net votes
Problem: I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent. The previous developer used two ways of declaring functions and I can't work out if there is a… Fix (from the top answer): 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…