BookClub Understand ECMAScript 6 - Weyjones/TravelPoster GitHub Wiki

Chapter 1 Block Bindings

use const by default, and only use let when you know a variable’s value needs to change. The rationale is that most variables should not change their value after initialization because unexpected value changes are a source of bugs.

Question: What is declaration hoisting? explain the following code:

function getValue(condition) {

    if (condition) {
        var value = "blue";

        // other code

        return value;
    } else {

        // value exists here with a value of undefined

        return null;
    }

    // value exists here with a value of undefined
}

Question: What is Block Scope in ES6? How is it different than function scope in ES5? Explain the following code:

function getValue(condition) {

    if (condition) {
        let value = "blue";

        // other code

        return value;
    } else {

        // value doesn't exist here

        return null;
    }

    // value doesn't exist here
}

Question: What's the difference between Var, Let and Const? How are they different in for-loop?

Question: Can an object declared with Const change?

Question: Can you use/access a let/const variable BEFORE it is declared?