JavaScript - Block scoping with let And const

ES6 introduced two new keywords let and const which provide different scoping than var variables.

let

It is blocked-scoped i.e it only exits within any kind of the curly bracket block.

const

It is also blocked-scoped but must be initialized with declaration. Also its value cannot be changed.

var (pre-existing scoping)

Not blocked-scoped. They scoped to either the containing function (if defined inside a function - also referred as local-scoped) or the whole script (if defined outside a function - referred as global-scoped).