0

in the following code if I use 'var' it outputs "undefined" and if I use 'let' it will produce and error "x is not defined"

function foo() {


    function bar() {
       console.log(x);
    }

    bar();

    var x = 14;

}

foo();

can some one explain it why

TheEhsanSarshar
  • 2,677
  • 22
  • 41

0 Answers0