{{announcement.body}}
{{announcement.title}}

Guide to New JavaScript Features Introduced at Google I/O 2019

DZone 's Guide to

Guide to New JavaScript Features Introduced at Google I/O 2019

In this article, we discuss new features in JavaScript, including iterations and asynchronous generators and new array and object methods.

· Web Dev Zone ·
Free Resource

google-sign-graffitti

On May 6 and 7, 2019, the most recent Google I/O conference was held. This is an annual technology event that has been organized by Google every year since 2008. The forum brings together developers from around the world to present and discuss topics related to Google products, open Internet technologies, and new trends in the software industry.

One of the biggest trends that was covered at this event was a series of changes with JavaScript. Mathias Bynens and Sathya Gunasekaran covered many of these changes in a talk titled: "What's new in JavaScript". This is a great video to check out. These two men have worked on Google's V8 JavaScript engine project, so they are very knowledgeable about the impact of these changes. However, we wanted to summarize the changes here.

You may also like: How JavaScript Actually Works: Part 1.

Recent Google Conference Highlights the Evolution of JavaScript

JavaScript is no longer a programming language that is only used to develop frontend web applications. Based on interviews with several programmers from the coworking space, JavaScript has become a powerful language and widely used for:

  • Desktop applications with Electron.

  • Multiplatform mobile applications with React Native.

According to the 2019 StackOverflow survey, JavaScript is the most popular programming language.

A number of new JavaScript features and specifications have been released. The 2019 Google I/O forum outlined all of these changes.

JavaScript Features Announced at Last Year’s Google I/O Conference

Multiple new JavaScript changes had originally been revealed in the 2018 Google I/O conference, but were not compatible with all browsers until now. In 2019, these functions are implemented in every major browser.

Iterations and Asynchronous Generator Features

Iterators can be described as pointers that sequentially run through data structure elements. These include every string, array, set, and map within these structures. The Symbol.iterator  key can be used to iterate through these features. The nextdefined method is also useful. This feature can return the properties listed below:

  • Value: This variable returns the value for the very next element in a given sequence called with the nextdefined method.

  •  Done: This Boolean variable references the secession of a sequence.

An iterator or generator can be used to asynchronously read data streams. This is very similar to the syntax of the command known as  async-await, but there are a couple of important differences.

This command will wait until the URL response has been received. After this condition is satisfied, fragments of data are released and appended to the variable. A while() function continues until the sequence is completed. You can see how these changes have made JavaScript cleaner and less detailed.

The loop-await-of continues receiving response data from the URL and the process is terminated once the stream is complete.

Finally for Your Promises

The new version of JavaScript uses the block for promises. This code is contained within the block and is executed after the promise is either rejected or resolved.

Option to Write Catch Blocks

You no longer need to pass an argument when writing a catch block.

Trimming on Various Sections of String

The trim function is most commonly used to remove white space from a string variable. However, you might not want to remove whitespace from the entire string. You can use the trimEnd and trimStart functions to delineate the parts of the string that you want to trim.

Spread Command for Objects

The spread operator will not only be available to use with arrays, but also in JavaScript objects. The spread syntax operator is valuable for object cloning.

Attributes of a Class

There are two improvements related to the attributes of a class. The first is to remove the builder function.

The constructor in the previous class is used to create an instance of the objects and assign a default value to the _country attribute. The underscore at the beginning of the variable name is a convention for declaring private attributes of the class.

However, it is only a convention and not something that is strictly applied. This means that anyone can access the _country property and could change the name of the destination country because the _country attribute remains publicly accessible.

Unless you make an internal change when assigning a value to the _country attribute, the function that assigns the value to the attribute previously retrieves the country name from the random function. In this way, the value cannot be assigned from the direct assignment to the instantiated object.

The syntax of classes is improved by removing class builder and directly initializing all top-level class attributes. The other significant improvement is making every private member truly private.

New Array Methods: flat and flatMap

The flat method is used to create a new array with all the elements and/or arrays that the main array may contain.

New Object.fromEntries() method

The  Object.fromEntries() method transforms a list of key-value pairs into an object. It produces a result contrary to the Object.entries() method.

With the Object.fromEntries() method, the opposite happens. That is, it converts an object into an array.


Further Reading

Topics:
javascript ,programming ,conference ,web dev ,react ,react native ,angular ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}