Variable javascript

what is the difference of
let myvariable and var myvariable

variables declared with var are function scoped and can be redeclared
this is allowed:

var myvariable = 1;
var myvariable = 2; 

variables declared with let are block scoped, and can’t be redeclared
this is not allowed:

let myvariable = 1;
let myvariable = 2; // this gives error and stops execution of code

let is the newest and it is best practive to avoid using var, but use let or const

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