Typescript

ECMAScript6 or ECMA2015 Features [Syntactical Sugar]

it helps write more cleaner and concise code!

Reference Project:

[git]Typescript-tutorial/ecma6-features

  1. Optional/Default parameter - initialze the funtional parameter to make it optional
    1. e.g function printNumber(inital,final=0,interval=1){}
  2. 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.
    1. e.g: `this is example of template String: ${some_var.value}`
  3. let const- apart from var keyword ecma6 offers others keyword for same purpose because of following advantage over var,
    1. var keyword does not obey the scope rule so let can be used in its place for probable bug free code
    2. const ensure that the single value is assigned
  4. for…of loop : earlier we had for..in but it returned index instead of element , so made the code more verbose.
  5. Lambdas or Arrow function: syntactical sugar and offers other advantages
    1. using this keyword in click event refer to browser scope so return unexpected result in such case arrow function is useful.
    2. Concise the verbose code
  6. 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
    1. Array De-structuring: values are assigned position wise
      • e.g arr=[1,2,3]; var [a ,b,c]=arr;
    2. 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;
  7. The Spread operator : used in case want to provide unlimited number of parameter to function
    1. e.g function myfun(a,b,…someValues){console.log(someValues)}; myfun(1,2,3,4,5,6,7,8);
  8. Computed properties : the common properties values of object can be assigned to global variable & is used as syntactical sugar.

Published by

Unknown's avatar

sevanand yadav

software engineer working as web developer having specialization in spring MVC with mysql,hibernate

Leave a comment