ECMAScript (ES) is a language specification which is created to standardize JavaScript. ES8 is the eighth version of the JavaScript language specification and is released in 2017. It is also known as ES2017. It is created to offer new features and new ways of working with JavaScript.

Features

  1. String padding

    Two functions are using with string for padding padStart and padEnd.These functions will pad the start or the end of the given string so that the result string reaches the target length. By default, spaces are padded with the resulting string.

    1. padStart
      Declaration:
      string.padStart(targetLength [, padString])
      Example:
      ‘es8’.padStart(6, ‘woof’); // ‘wooes8’
      ‘es8’.padStart(7, ‘0’); // ‘0000es8’
    2. padEnd
      Declaration:
      string.padEnd(targetLength [, padString])
      example:
      ‘es8’.padEnd(7, ‘6’); // ‘es86666’
      ‘es8’.padEnd(14, ‘wow’); // ‘es8wowwowwowwo’
  2. Object.values and Object.entries

    1. Object.values

      An array of a given object’s own enumerable property values will be returned when this function is called.

      The function should be declared as:
      Object.values(obj)

      Here the obj parameter is the source object for the operation which can be an object or an array.

      (That is, if indexes of an object is [10, 20, 30] then { 0: 10, 1: 20, 2: 30 }).
      For example:
      const obj = { a: ‘xxx’, b: 1 };
      Object.values(obj);  will give the output [‘xxx’, 1]
      const obj = [‘t’, ‘s’, ‘c’];  // same as { 0: ‘t’, 1: ‘s’, 2: ‘c’ };
      Object.values(obj);  will give the output [‘e’, ‘s’, ‘8’]

      While using numeric keys, the values are returning in a numerical order according to the keys.

      const obj = { 10: ‘aa’, 1: ‘bbb’, 3: ‘ccc’ };
      Object.values(obj); will give the output [‘bbb’, ‘ccc’, ‘aaa’]
      Object.values(‘es8’); will give the output [‘e’, ‘s’, ‘8’]

    2. Object.entries

      An array of input object’s own enumerable property [key, value] pairs, in the order same as Object.values.

      Function should be declared as:
      Object.entries(obj);
      For example:
      const obj = { a: ‘xxx’, b: 1 };
      Object.entries(obj); will give the output [[’a’, ‘xxx’], [’b’, 1]]
      const obj = [’e’, ‘s’, ‘8’];
      Object.entries(obj); will give the output [[’0’, ‘e’], [’1’, ‘s’], [’2’, ‘8’]]
      const obj = { 10: ‘aaa’, 1: ‘bbb’, 3: ‘ccc’ };
      Object.entries(obj); will give the output [[’1’, ‘bbb’], [’3’, ‘ccc’], [’10’, ‘aaa’]]
      Object.entries(‘es8’); will give the output [[‘0’, ‘e’], [‘1’, ‘s’], [‘2’, ‘8’]]

  3. Object.getOwnPropertyDescriptors

    This function returns all of the own property (non-inherited property) descriptors of an object.
    The possible attributes for the returned objects result are configurable, writable, set, get, value, enumerable.
    The function can be declared as:

    Object.getOwnPropertyDescriptors(obj) //Here obj is the source object.For example:
    const object1 = {property1: 24};
    const descriptors1 = Object.getOwnPropertyDescriptors(object1);
    console.log(descriptors1.property1.writable);
    // expected output: true
    console.log(descriptors1.property1.value);
    // expected output: 24

  4. Trailing commas in function parameter lists and calls

    It is the ability of the compiler not to raise a SyntaxError when we add a comma at the end of the list unnecessarily.
    It helps us to make a valid function declaration even adding commas at the end of the list.

    function test(var1, var2, var3,) {
    // …
    }
    It can be applied to function calls too: test(10, 20, 30,);

  5. Shared memory and atomics

    To handle concurrency effectively, SharedArrayBuffer and Atomics are introduced here.

    • Shared Array Buffers:

      For higher-level concurrency abstractions, they are the building blocks. By using this the sharing of the bytes of a SharedArrayBuffer object between multiple employees and the main thread can be done in a quick way

    • Atomics :

      In the process of reading or writing, nothing will interrupt these processes. Using Atomics object we can ensure that. So these operations will be finished before the next one starts.

  6. Async functions

    It helps us to work with asynchronous functions in an easy way.
    During the declaration of an async function, it defines an asynchronous function and returns an AsyncFunction object.

    An async function returns a Promise when it is called.

    The Promise will get resolved with the returned value which is returned by the async function.

    When an exception is thrown by the async function, with the thrown value Promise will be get rejected.

    For example:function loadTestContent() {
    return new Promise((resolve, reject) => {
    setTimeout(() => {
    resolve(‘hello’);
    }, 3000);
    });
    }async function getTestContent() {
    const test_text = await loadTestContent();
    console.log(test_text );
    }

    console.log(‘it will call the function’);
    getTestContent();
    console.log(‘it called the function’);

    After running , this will print:

    ‘it will call the function’ // synchronous
    ‘it called the function’ // synchronous
    ‘hello’ // asynchronous (after 3 seconds)

    By analyzing, we can see that the function call doesn’t block the flow.
    We have to keep in mind that an async function always returns a promise and an ‘await’ keyword must be used in functions marked with the async keyword.

[tagline_box backgroundcolor=”description=” shadow=”no” shadowopacity=”0.7″ border=”1px” bordercolor=”” highlightposition=”top” content_alignment=”left” link=”” linktarget=”_self” modal=”” button_size=”” button_shape=”” button_type=”” buttoncolor=”” button=”” title=”” description=”If you have any queries on Features Of ES8 feel free to leave us a message and our representative will get back to you.

” margin_top=”50px” margin_bottom=”” animation_type=”slide” animation_direction=”left” animation_speed=”0.3″ class=”” id=””]

    [/tagline_box]