Wednesday, May 23, 2018

ES6 Javascript

ES6 is backward compatible with ES5.

let :- helps in avoiding variable hoisting. Default supports block scoping.

const :- constant variable. usually declared in capital letters. Default supports block scoping.

Block scoping

Array functions :- Similar like lambda. Array function can not change by bind, call functions.
    In arrow functions, 'this' is not the function context of the element but the context in which function running.

Default function parameter :- For undefined values, function will use default value.

Rest and Spread:- Rest means gathering all elements together & putting in single array.
... is rest syntax.
... on array object acts as spread i.e. to separate elements


Object literal extensions

for ... of loops
 cimpatible
Template Literals :- String template are backword compatibility.


Destructuring :- Taking element from array and assigning to variables. Array & objects can be destructured.


module :- gets executed only once.
import statement gets hoisted & gets executed first.
By default modules are loaded in strict mode.
variables, functions can be exported from module.
exported objects are readonly. But properties of object can be modified.

'import *'  exports all variables, functions.

class is function.

ES5 Java Script

ES5  :-

Javascript file or code should be included in the end of body section of HTML.
tag will detect if javascript is turned of.

Variables :- var variables re dynamically typed.
use strict mode.
typeof will tell data type.

primitive datatype :-  number(int, float), string, boolean
complex datatype :- object (array, json etc), function

Functions can be assigned to variables, can be executed using ().

for -- in  can be used for printing fields of object.

variable name can start with $, _ or letters. Numbers & symbols are not allowed as first letter.

Hoisting :- means two pass compilation process.
                  In Pass1 :- All declarations are located & identifiers are known by compiler.
                  In Pass2 :- Execution occurs. Variables declared after usage also works as they are known to compiler in Pass1.
                  In Hoisting step all variables are assigned 'undefined' value.

Infinity(Number.POSITIVE_INFINITY), -Infinity (Number.NEGATIVE_INFINITY)

string :-- double quotes, single quotes are same.

!!  :- Two NOT convertes variable to boolean.
undefined has type as 'undefined'.
null has type as object.

this === window.          window is global scope.