Using variables


I noticed that when using the “let” key for variables and reasigning that same variable that you don’t need to rewrite the “let” keyword again. Why? if Javascript understands this, then why do we need to write it in the first place?



let is a declaration keyword. Once a variable is declared, we have only to define it. We can assign new values directly to the variable.

let temp = 0

temp += 10

Recall that let has block scope.

    let temp = 0;

    temp += 10;

We cannot access temp outside of the block.

var is still useful, and should not be tossed aside. let added block scope that JS did not have previous to ES2015.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.