My Code


Someone could explain me the difference between let, var, and const?
I saw other coders that used var userName = ""
or in point 3 the hint suggests const userQuestion = 'blablabla'

let userName = '';

userName ? console.log(`Hello, ${userName}`) : console.log('Hello!');


let userQuestion = 'Do I go in Amsterdam?';

console.log(`The User asked: ${userQuestion}`);

let randomNumber = Math.floor(Math.random() * 8);

let eightBall = '';

switch (randomNumber) {
        case 0:
        eightBall = 'It is certain';
    case 1:
        eightBall = 'It is decidedly so';
    case 2:
        eightBall = 'Reply hazy try again';
    case 3:
        eightBall = 'Cannot predict now';
        case 4:
        eightBall = 'Do not count on it';
    case 5:
        eightBall = 'My sources say no';
    case 6:
        eightBall = 'Outlook not so good';
    case 7:
        eightBall = 'Signs point to yes';

console.log(`The eight ball answered: ${eightBall}`);


let and const where introduced in es6, they are “new”, before we only had var

the problem is that var has a functional scope (or global if there no enclosing function)

so let and const where introduced to give us block scope. For example:

if (true){
    var x = true; // global scope, no enclosing function
    let y = true; // block scope, only exist within if clause

console.log(y); // will produce error

the difference between let and const? A constant variable can’t be changed/re-assigned:

const a = 'hello world'
a = 'error' // will produce error


Thanks a lot, stetim94!