Below is the list of major upgrades
- 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.
- Classes: The explicit keyword ‘Class’ will definitely make it easier for people coming from any other Object oriented programming language.
- Additional String methods: Few convenience methods have been added to String prototype. Few of these are
- prototype.startsWith: This functions checks if the string starts with the characters of another string. Return value is either true or false.
- prototype.endsWith: This function checks if the string ends with the characters of another string. Return value is either true or false.
- prototype.includes: This function checks if a string is found within another strings. Return value is true or false.
- 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.
- Additional Array methods: Few more methods have been added to Array prototype along with new static class methods. Few of these are
- 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.
- of: Creates a new array with variable number of arguments regardless type or number of arguments.
- 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.
- 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.
- prototype.fill: Fill method fills all the elements of the array from start index to end index with a static value.
- Additional Math methods: Methods have been added to math object. These are
- sign: This function returns the sign of the number indicating whether it is a positive number, negative number or zero.
- trunc: This function returns integer part of the number by removing any fractional part.
- cbrt: This method return the cube root of the input number.
- Destructuring: With destructuring in place, multiple variables can be assigned values in one go.
- 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.
- 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.
- To check which browsers support which features, go to https://kangax.github.io/compat-table/es6/.
- 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.
- Link to original ES2015 specification: http://www.ecma-international.org/ecma-262/6.0/
About the author:
“Harshit is a technology enthusiast and has keen interest in programming. He holds aB.Tech. degree in Computer Science from JIIT, Noida and currently works as Front-end Developer at SAP. He is also a state level table tennis player. Apart from this he likes to unwind by watching movies and English sitcoms. He is based out of Delhi and you can reach out to him at https://in.linkedin.com/pub/harshit-jain/2a/129/bb5
If you also wish to showcase your blog here, please see GBlog for guest blog writing on GeeksforGeeks.