Different between let and var


what is the different between let and var ?


to truly understand the difference, we need to look at var, let and const

both let and const where introduced in es6, allowing block scope. var has a functional local scope or global scope, let me show you what i mean:

if true:
    var global_scope = "hello world"
    let block_scope = "hello world"

console.log(global_scope) // outputs: hello world
console.log(block_scope) // throws error

block_scope only exist within the if clause/block.

what is the difference between const and let? a constant variable can’t be re-assigned:

const constant_variable = "hello world"
constant_variable = "this will throw an error"


That helped a lot for me