JavaScript var vs let vs const

Code Snippets

var scope

// var is global/functional scope
const name = "Faheem Global";

function vFunction(){
    const subs = 84;    
}

vFunction();

if(true) {
    const planet = "Earth";
}

console.log(name);
console.log(window.name);

// console.log(subs);
// console.log(window.subs);

// console.log(planet);
// console.log(window.planet);

const name = "hehe";

let scope

// var is global/functional scope
let name = "Faheem Global";

function vFunction(){
    let subs = 84;    
}

vFunction();

if(true) {
    let planet = "Earth";
}

console.log(name);
console.log(window.name);

// console.log(subs);
// console.log(window.subs);

// console.log(planet);
// console.log(window.planet);

let name = "hehe";

const scope

// var is global/functional scope
const name = "Faheem Global";

function vFunction(){
    const subs = 84;    
}

vFunction();

if(true) {
    const planet = "Earth";
}

console.log(name);
console.log(window.name);

// console.log(subs);
// console.log(window.subs);

// console.log(planet);
// console.log(window.planet);

const name = "hehe";

hoisting

function hehe(){
    console.log("Already hoisted.");

    console.log(vName);
    console.log(lName);
    console.log(cName);

    var vName = 'Faheem using var';
    let lName = 'Faheem using let';
    const cName = 'Faheem using const';
}

hehe();

https://developers.google.com/web/updates/2019/12/devtools

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

https://stackoverflow.com/questions/762011/whats-the-difference-between-using-let-and-var