Open In App

ES2015: Latest version of JavaScript

Improve
Improve
Like Article
Like
Save
Share
Report

ES2015 is the latest version of JavaScript programming language. It is the first major upgrade to JavaScript since 1997. It was approved in June 2015 by ECMA international, an association responsible for approving ECMA standards which programming languages like JavaScript, CoffeeScript and TypeScript follows. The name of this version of JavaScript has undergone multiple changes starting from Harmony to ES6 to ES2015. Before ES2015, ECMAScript was named after version numbers. It was only recently that it was decided that it will be named according to the year of release. Thus the name changed from ES6 to ES2015.

Below is the list of major upgrades

  1. Block Scoping: JavaScript variable scoping along with concepts of variable hoisting has been confusing developers since long. Up until ES5, variables either have a global scope or a function level scope. The lack of block scoping was a real pain especially for people coming from other programming languages like C++/Java. With introduction of “let” and “const” keywords in ES2015, life is surely going to get a little bit easier for JavaScript programmers.
  2. Promises: Promises provide a mechanism to handle asynchronous calls. With ES2015, JavaScript has in-build mechanism to register and handle promises
  3. Arrow Functions: With the addition of arrow functions, programmers will have to type in fewer keystrokes to declare a function. Arrow functions will also help to remove the statement like “self = this” as arrow function passes the “this” variable of the caller function inside the called function.
  4. Modules: Till now, to load modules, developers had to depend on libraries like commonJS or requireJS. With ES2015, concept of modules makes its way into JavaScript with module loader mechanism.
  5. Classes: The explicit keyword ‘Class’ will definitely make it easier for people coming from any other Object oriented programming language.
  6. Additional String methods: Few convenience methods have been added to String prototype. Few of these are
    1. prototype.startsWith: This functions checks if the string starts with the characters of another string. Return value is either true or false.
    2. prototype.endsWith: This function checks if the string ends with the characters of another string. Return value is either true or false.
    3. prototype.includes: This function checks if a string is found within another strings. Return value is true or false.
    4. prototype.repeat: This function takes as an argument an integer value say i. It returns a string containing a string which contains the string repeated i times.
  7. Additional Array methods: Few more methods have been added to Array prototype along with new static class methods. Few of these are
    1. from: Create a new array from an array like or iterable object. It can also apply a map function to all the items of the array.
    2. of: Creates a new array with variable number of arguments regardless type or number of arguments.
    3. prototype.find: Find function takes in as an argument a callback function which is called for each element. If callback returns true for any element, that element is immediately returned. If callback doesn’t return true for any element, undefined is returned.
    4. prototype.findIndex: This function is similar to Array.prototype.find(). The only difference is that instead of returning the value, it returns the index of that value in the array.
    5. prototype.fill: Fill method fills all the elements of the array from start index to end index with a static value.
  8. Additional Math methods: Methods have been added to math object. These are
    1. sign: This function returns the sign of the number indicating whether it is a positive number, negative number or zero.
    2. trunc: This function returns integer part of the number by removing any fractional part.
    3. cbrt: This method return the cube root of the input number.
  9. Destructuring: With destructuring in place, multiple variables can be assigned values in one go.
  10. Parameters default values: Function parameters can now have default values. So if while calling user misses passing the value to the argument, the default value will be used. With this feature, initial input parameter validations can now be avoided in functions.
  11. Template Literals: String interpolation is now easy with the use of backticks. To place a variable in between a string, you no longer need to break the string and use ‘+’ operator to concatenate strings. Just place the variable between a $ and curly braces and you are done. Multiline strings are also allowed now inside backticks.

As of now, browsers do not support all the features of ES2015, though eventually they will.

 Useful links:

  1. To check which browsers support which features, go to https://kangax.github.io/compat-table/es6/.
  2. This article covered major features of ES2015 briefly. If you are interested in more, complete list of features is available on http://es6-features.org/ with examples.
  3. Link to original ES2015 specification: http://www.ecma-international.org/ecma-262/6.0/
  4. To understand difference between JavaScript and ECMAScript, see the answer on http://stackoverflow.com/questions/912479/what-is-the-difference-between-javascript-and-ecmascript/30113184#30113184

This article is contributed by Harshit Jain

If you also wish to showcase your blog here, please see GBlog for guest blog writing on GeeksforGeeks.


Last Updated : 04 Aug, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads