Skip to main content
2 of 2
fix undefined behavior example
Austin
  • 716
  • 1
  • 5
  • 7

The main practical difference is hoisting. For example:

foo(); // alerts 'hello'
function foo() {alert('hello');}

vs

foo(); // throws an error since foo is undefined
var foo = function() {alert('hello');}

Also, this is undefined behavior

function foo(){
  if (true) {
    function bar(){}
  }
  bar();
}

while this is ok.

function foo(){
  if (true) {
    var bar = function(){}
  }
  bar();
}
Austin
  • 716
  • 1
  • 5
  • 7