Difference between 'let' and 'var' variables

Hello everyone,

In javascript variables course, there are 2 types of variables i.e. let and var.

So my doubt is, When ‘let’ and ‘var’ variables are called outside the scope ‘{ }’ then both are not printed it shows error so what is the difference between the two?

1 Like

please share your code to find your error.
Below my code is working

{
    var x = 10
    let y = 20
}

console.log(x); // will print 10
console.log(y); // will not print because Uncaught ReferenceError: y is not defined