Wednesday, June 17, 2020

The New Features in JavaScript ES2020 Every Developer Should Be Excited About

The release of ES6 in 2015 created a remarkable impact in JavaScript, since then it has been evolving fast with tons of new features coming out in each phase. The new versions of the programming language have been updated yearly, with new structured language feature being finalized faster than ever. The new features are getting incorporated into modern browsers and other JavaScript engines making it more dynamic.
In 2019, many new features shot up to in ‘Stage 3’ phase, meaning the closeness of being finalized, and browsers getting support for these features in present day.
ES2020 is the version of ECMA Script corresponding to the year 2020. This version doesn’t include as many new features as those that emerged in ES6 (2015). However, many useful features have been incorporated and the new and improved ES2020 features of JavaScript are now available widely.
In this article, we will look into the recent features that came up in the systems of programming language.
  • BigInt : Biglnt is the special numeric type that provides support for integers of arbitrary length. This is the most anticipated features in JavaScript. The main function allows developers to have greater integer representation in the code for data processing for data handling. At present, the maximum number can be stored as an integer is pow(2, 53) – 1. But BigInt allows proceeding even beyond that. A BigInt is created by appending n to the end of an integer literal10n or by calling the function BigInt(). BigInt is close to Number in some ways, but also differs in a few key matters that are it cannot be used with methods in the built-in Math object and cannot be mixed with instances of Number in operations. They are coerced to the same type.
  • Dynamic Import: Dynamic Import imports JavaScript files dynamically as it modules in the application procedure. It assures a promise for the module namespace object of the requested module. Therefore, the imports can now be assigned to a variable using async/await. This feature will also help in ship on-demand-request code, better known as code splitting, without the overhead of other module bundlers. Also conditionally load code can be done in an if-else block if one feels like. The better concept is that one can actually import a module, and so it never infects the global namespace.
  • Nullish Coalescing: Nullish coalescing adds the capability to truly check nullish values instead of falsey values. In JavaScript, there are lot of values that are falsey, like empty strings, the number 0, undefined, null, false, NaN, etc. However, one might want to check if a variable is nullish, that means if it’s either undefined or null, and like when it’s okay for a variable to have an empty string, or even a false value. In that logic, one might use the new nullish coalescing operator, ??. Also the OR operator always returns a truthy value, whereas the nullish operator returns a non-nulllish value.
  • Optional Chaining: Optional chaining program helps in to access deeply nested object properties without worrying if the property exists or not. If the property doesn’t exist, undefined will be returned. This works on object properties, but also can function over calls and arrays. While looking for a property value in a tree-like structure, one can check whether intermediate nodes exist. The Optional Chaining permits the programmers to handle the cases without assigning intermediate results in short term variables. Again, many API return either an object or undefined, and one might want to extract a property from the result only when it’s not null. When some value other than undefined is desired for the missing case, then this can usually be handled with the Nullish coalescing operator which we talked about previously.
  • Promise.allSettled: As the name suggests, the Promise.allSettled method accepts an array of Promises and only resolves when all of them are settled. They are either resolved fully or rejected. This was not available before but some close implementations like race and all were much available. This actually brings "Just run all promises – I don’t care about the results" instantly to JavaScript.
  • GlobalThis: ES2020 brings the feature global. This which refers to the global object no matter in what condition a code is executed. This was prevalent earlier but was not standardized before ES10. Some cross-platform JavaScript code that is wrote could run on Node, in the browser environment, and also inside web-workers. Therefore it was hard getting hold of the global object. This is due to; it is window for browsers, global for Node, and self for web workers. The more the runtimes, the global object will be different as well.
For-in Mechanics: ECMA-262 standard leaves the order of for (a in b) fully unspecified, but real engines tend to be constant in some cases. There were efforts to get consensus on a complete specification of the order of for-in which have repeatedly failed. This happened because all engines have their own idiosyncratic implementations that results of a great deal of work and that they don’t really want to revisit. Therefore, different engines have agreed on how properties are iterated when using for (a in b) control structure so that the behavior is standardized.

Conclusion

The consistency and speed with which the JavaScript community is revolving is really noteworthy. It is delightful to see how JavaScript evolved the language systems and became one of the most flexible and versatile language of all time in the coding world. JavaScript is a live language which is much healthy for web development. The appearance of ES6 in 2015 has clearly marked upon the continuance of the system. In this article, we’ve reviewed the features that arise in ES2020. However, many of these features may not be essential for the development of the web application, none the less; the possibilities could be achieved with lots of verbosity.

No comments:

Post a Comment