ECMAScript6 or ECMA2015 Features [Syntactical Sugar]
it helps write more cleaner and concise code!
Reference Project:
[git]Typescript-tutorial/ecma6-features
Optional/Default parameter - initialze the funtional parameter to make it optionale.g function printNumber(inital,final=0,interval=1){}
- Template String – to create a string by using variable it must be enclosed in back-tick and variable be embedded in ${var_name},it does away the problem of concatenation i.e using plus(+) sign to concatenate.
- e.g: `this is example of template String: ${some_var.value}`
- let const- apart from var keyword ecma6 offers others keyword for same purpose because of following advantage over var,
- var keyword does not obey the scope rule so let can be used in its place for probable bug free code
- const ensure that the single value is assigned
- for…of loop : earlier we had for..in but it returned index instead of element , so made the code more verbose.
- Lambdas or Arrow function: syntactical sugar and offers other advantages
- using this keyword in click event refer to browser scope so return unexpected result in such case arrow function is useful.
- Concise the verbose code
- De-structuring: it is way of assigning multiple variable some value from single object in single line. It is possible for both Array as well as Object
- Array De-structuring: values are assigned position wise
- e.g arr=[1,2,3]; var [a ,b,c]=arr;
- Object de-structuring: values are assigned to variables based on properties name from object and the variable name can be updated using : operator
- e.g var someObj={id:1,name:”Sevanand”};var {name: myname,id}= someObj;
- Array De-structuring: values are assigned position wise
- The Spread operator : used in case want to provide unlimited number of parameter to function
- e.g function myfun(a,b,…someValues){console.log(someValues)}; myfun(1,2,3,4,5,6,7,8);
- Computed properties : the common properties values of object can be assigned to global variable & is used as syntactical sugar.