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