Tag Archives: var

Difference Between JavaScript var and let

var : A variable defined using a var statement is known throughout the function it is defined in, from the start of the function.

Example:

{
    var i = 5;
}
//i can be used here

let : A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

Example:

{
    let i = 5;
}
//i can be used here