Javascript Notes
- Quick Links
- Favorite Javascript Books
- ECMAScript 6 (ES 2015)
- Basic Language
- React
- See how ES compiles to javascript: https://babeljs.io/repl/
- A re-introduction to javascript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Are-introductionto_JavaScript
- Functional JavaScript (this one is awesome!)
- Javascript: The Good Parts
Quick Links
Favorite Javascript Books
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.