Skip to content
Home » Features of ECMAScript 6 (ES6)

Features of ECMAScript 6 (ES6)

ES6 main screen
  1. Variable:
    • var (ES5): Variable scope is available within the function in which it is declared.
    • let (ES6):
      • let scope works only within the block in which it is declared like {}. be it function(){}, if(){} or just {}, etc.
      • Does not allow redeclaring variable within the scope (Reduces unnecessary redeclaration of the same variable).
    • const (ES6)
      • Another way to declare block-scoped variables and value must be assigned to the variable.
      • Throws JS error if const variable’s value is changed or if no value is set immediately during declaration.
      • But object property or array member can be changed if constant is an object or array that can add/remove property/member or can change the value.
  2. Parameters:
    • Default Values in function signature:
    • Default Indefinite Rest Parameters:
  3. Template Literals:
  4. Arrow Functions:
    • Makes short and concise code. The return statement is implicitly added.
    • Must provide parentheses with zero or more than one arguments.
    • To write multiple statements, put the function expression in a block ({ … }).
    • It also inherits ‘this’ and arguments from the surrounding context.
  5. Array:
  6. String:
    • Many Simple, effective and convenience methods are added to the String prototype.
    • It eliminates workarounds with the method indexOf().
  7. Maps:
    • New data structure to store key values pair of any type.
  8. Class Constructor and Methods:
    • Class-based model.
  9. Math:
    • New methods have been added to the Math object.
      • Math.sign: returns sign of a number as 1, -1 or 0.
        Math.sign(5); // 1
        Math.sign(-9); // -1
      • Math.trunc: returns passed number without fractional digits.
        Math.trunc(5.9); // 5
        Math.trunc(5.123); // 5
      • Math.cbrt: returns cube root of a number.
        Math.cbrt(64); // 4
  10. Spread Operator:
    • It is a very convenient syntax to expand elements of an array in specific places, such as arguments in function calls.
    • Also, no need to call apply() method for the workaround.
  11. Destructuring:
    • Provides a convenient way to extract data from objects or arrays.
    • Values can be assigned to multiple variables in one shot. and with this, you can also easily swap variable values.
    • It also works with objects (need to make sure to have matching keys)
    • This mechanism can also be used to change variable names.
    • Can be used for multiple return values.
    • Can be used to assign default values to argument objects.
  12. Modules:
    • It includes both a new syntax and a loader mechanism for modules.
      // lib/math.js (create a math.js file in lib folder to export variable and methods.export function sum(x, y) {
      return x + y;
      }
      export var pi = 3.141593;// app.js (create your app.js file to import methods/variable from module created above.
      import { sum, pi } from “lib/math”;
      console.log(‘2π = ‘ + sum(pi, pi));
  13. Symbols:
    • Symbols are a new primitive data type, like Number and String.
    • It can be used to create unique identifiers for object properties or can create unique constants.
      const MY_CONSTANT = Symbol();

I hope this post gives you some clear and simple idea of what is there in ES6. More can be read from below reference links:

References:

Leave a Reply

Your email address will not be published. Required fields are marked *

4 Shares
Tweet
Pin
Share
Share4
Share