Tuesday, March 24, 2020

About ES6 and it's new feature documentation ?


Introduction of ES6



->ECMA script is a scripting language standard and specification

 1)JavaScript
 2)Jscript
 3)ActionScript






->What is ES6?

  ->The most recent version of ECMAScript/ JavaScript
  ->very significant update with many changes
  ->first major update since ES5(2009)
  ->ES6 and ES2015 are the same thing




->Goals of ES6

  ->Be taken more seriously
  ->Fix some issues from ES5
  ->Backward compatibility -ES5 should work in ES6
  ->Modern syntax
  ->Better sccaling and better for big applications
  ->new feature in standard library






->What's New? An Overview

  ->let and const Declaration
  ->classes and inheritance
  ->Arrow function
  ->javascript classes
  ->Default parameter values
  ->Array.find()
  ->Array.findIndex()
  ->Exponentiation(**) (Ecma script 2016)







let's make dive into ES6



1)let

->allow to declare a variable with block scope
->eg:
  var x = 10;
  //here x is 10
  {
    let x = 2;
//here x is 2
  }
  // here x is 10





2)const

->allow  to declare a constant.
->similar to let variable, except that the value cannot be changed
->eg:
  var x = 10;
  //here x is 10
  {
    const x = 2;
//here x is 2
  }
  //here x is 10






3)Arrow functions

->short syntax for writing function expressions.
->using const is safer than using var,
  because a function expression is always constant value
->eg:
  //ES5
  var x = function(x, y){
  return x*y;
  }
  //ES6
  const x = (x, y) => x*y;
  
->eg:
  const x = (x,y) =>{return x*y };






4)Classes

->a class is a type of function, but instead of using the keyword function to
  initiate it,we use the keyword class, and the properties are assigned inside
  a constructor() method.
->use the keyword class to create a class, and always add a constructor method.
->the constructor method is called each time the class object is initialized.
->eg:
  class Car{
    constructor(brand){
  this.carname = brand;
}
  }
  mycar = new Car("Ford");





5)Default parameter values

->ES6 allows function parameter to have default value
->eg:
  function myFunnction(x, y = 10){
    // y is 10 if not passed and undefined
return x + y;
  }
  myFunction(5);  //will return 15
  myFunction(5,5);  // will return 10








6)Array.find()

->returns the value of the first array element that passes a test function
->the test function takes 3 arguments:
  1)the item value
  2)the item index
  3)the array itself
->eg:
  var numbers = [4,9,16,25,29];
  var first = numbers.find(myFunction);
  function myFunction(value, index, array){
    return value > 18;
  }








5)Array.findIndex()

->It retuens the index of the first array element that passes a test function
->It takes three arguments
  1)the item value
  2)the item index
  3)the array itself
->eg:
  var numbers = [4,9,16,25,29];
  var first = numbers.findIndex(myFunction);
  function myFunction(value, index, array){
    return value > 18;
  }






6)New number properties

->ES6 added the following properties to the number object
->EPSILON
->MIN_SAFE_INTEGER
->MAX_SAFE_INTEGER
->eg:
  var x = Number.EPSILON
  var x = Number.MIN_SAFE_INTEGER
  var x = Number.MAX_SAFE_INTEGER







7)New number methods

->ES6 added 2 new methods to the number object
->Number.isInteger()
  ->method returns true if the argumment is an integer
  ->eg:
    Number.isInteger(10);  // return true
    Number.isInteger(10.3);  // return false

->Number.isSafeInteger()
  ->method return true if the argument is a safe integer
  ->eg:
    Number.isSafeInter(10);  // returns true
    Number.isSafeInteger(1222234435454565554432332);  // return false






8)New global methods

->ES6 added 2 new global number methods
->isFinite()
  ->method return false if the argument is Infinity or NaN
  ->otherwise return true
  ->eg:
     isFinite(10/0);  // return false
     isFinite(10/1);  // return true

->isNaN()
  ->method return true if the argument is NaN.Otherwise it returns false
  ->eg:
    isNaN("hello");  // return true







9)Exponentiation Operator

->operator (**) raises the first operand to the power of the second operand.
->eg:
  var x = 5;
  var z = x ** 2;    // z = 25 












No comments:

Post a Comment