has w3schools even updated to es6? They are not known for there update speed (among other problems), it used to be horrible, w3schools is better but still not really good
var, lets look at an example:
var one = "global";
var two = "local";
console.log("inside the function: ")
example(); // call the function to execute
console.log("outside the function: ");
one has a global scope, i can access it anywhere.
two has a local scope, it only exist inside the function. If you try to log
two to the console outside the function (uncomment last line), you will get an error.
var gives two options: global or local scope
in es6 (released in 2015, which could be deduced from emcascript2015 name) introduced
const where introduced. We can create local and global variable with
let just like
const have a block scope where as
var has a function(al) scope.
let one = "block scope"
var two = "functional scope"
console.log("inside the if clause/block: ");
console.log("outside the if clause/block: ");
two are declared within the if block/clause. however,
one only exist within if block/clause given it has a block scope. While
two has a functional scope, so it can be accessed after
if clause (but within the function) while
one can not be accessed outside the if clause/block
same as before, run the example, then uncomment the comment, and you will you get an error.
so we have 4 things:
I hope this helped.