Variables
- keyword const, to declare a constant.
- Number:
- Number.NEGATIVE_INFINITY<Number.MIN_VALUE<Number.MAX_VALUE<Number.POSITIVE_INFINITY.
- Math is an "object" with the most common mathematic functions.
- Some useful method of Number: parseInt(), parseFloat(), isNaN(), isInfinite().
- Multiline string, useful to include variable values into the string:
var a=2; var b=2; var myString=`this is my value ${a+b} `;
The if statement
- To test if an array is empty, simply use if(myArray.length) not if(myArray.length>0).
- To test if a string is void use if(myString).
- Test only if an object is null if(myObj===null) not if it's null and undefined.
The scope
The scope is a "nested chain": the variable definition is searched in the nested scope, if there isn't then it's search in the upper scope.
- more about scope in Stack Overflow
- Immediately Invoked Function Expression on wikipedia
- Loops and if statement don't have their own scope in ES5, but ES6 introduced it (key-word let).
Functions
The functions parameters are stored in an object (arguments), similar to an array, so it's possible to retrive parameters with: arguments[i].
Collections
- Array
- it can stores several type.
- it's a map, the key is the index. The length() method return the last index plus 1, so
var a=2; var myArray=[]; myArray[25]="myLastObject"; console.log(myArray.length()); //print 26
- Usefull methods: foreach, concat, join, pop, push, shift, unshift, reverse, sort.
- Maps, only in ES6.
- Sets, only in ES6.
Tools
- bower, package manager.
- npm, pakage manager.
- javascriptlint
- gulp, builder, it's possible run several task (lint, minify resources..).
No comments:
Post a Comment