1. ECMAScript 6 (ES 2015)
  2. Basic Language
    1. Prototype
    2. Accessing Object Properties
  3. React
    1. setState

    ECMAScript 6 (ES 2015)

    http://www.ecma-international.org/ecma-262/6.0/ECMA-262.pdf

    This version introduces the concept of ES6 modules and the import syntax.

    https://github.com/lukehoban/es6features

    Basic Language

    Prototype

    All objects created from object literals are linked to Object.prototype.

    Accessing Object Properties

    When you try to access a property that does not exist inside an object, javascript gives undefined.

    myobject.dne
    // undefined
    

    If you try to access a property inside undefined, you get a type exception

    myobject.dne.reallydne
    // throws "TypeError"
    

    To guard against this, use &&

    myobject.dne && myobject.dne.reallydne
    // undefined
    

    React

    setState

    Two forms of setState, either just pass an object:

    this.setState({
      something: "changed"
    });
    

    Or pass a function to get access to previous state and props:

    this.setState((prevState, props) => ({
      counter: prevState.counter + props.increment
    }));
    

    setState merges the object passed (or the result from the function passed) into the components state.