dimanche 15 juillet 2018

Scope in Javascript, using let

let king = 'John';

if(true) {
    let king = 'Sam';

    if(true) {
        let king = 'Ram';
        console.log(king);
        }
    }

if(true){
    console.log("This is second part:"+ king);
    }

output: Ram This is second part: John;

Why in the second log its showing John, when the king is already changed to Ram?

Aucun commentaire:

Enregistrer un commentaire