Member-only story
7 New Features Shipping With ES2020
GlobalThis, optional chaining, private fields in classes, the nullish coalescing operator, and more
As you might know, since ES6 in 2015, a new version of ECMAScript is released each year, by Ecma International’s TC39. ECMAScript 2020 is the 11th edition of the ECMAScript Language Specification.
This new iteration comes with its own batch of new features — let’s review them!
1. ‘globalThis’
The JavaScript language is quite popular now and can be used in a wide variety of environments — in web browsers, of course, but JavaScript can also be run server-side, on smartphones, robotically, etc.
Each environment comes with its own object model and syntax to access the global object. Because of that, it can be tough to write JavaScript code that works in multiple environments:
// browser environment
console.log(window);
// node.js environment
console.log(global);
// Service worker environment
console.log(self);// ...
It is, of course, possible to standardize it across multiple platforms by writing a function that checks for the current environment, but this won’t be needed anymore!