snippet

When to use var, let and const on Javascript, what is a best practice ?

var myVar = "Hello";   // Use this for a global scope, you can change its value once declared
const myConst = "World"; // Once defined you cannot change its value, it also belongs to the global scope of your application just like var.
let myLet = "!";   // The scope of this declaration is limited to the declaration block, ideal for example in functions, iterations but also in conditions.
Related snippets