Guide to New JavaScript Features Introduced at Google I/O 2019
Join the DZone community and get the full member experience.
Join For FreeOn 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 developers worldwide to present and discuss topics related to Google products, open Internet technologies, and new trends in the software industry.
One of the biggest trends covered at this event was a series of changes to 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 used only to develop front-end web applications. Based on interviews with several programmers from the coworking space, JavaScript has become a powerful language and is 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.
Several new JavaScript features and specifications have been released. The 2019 Google I/O forum outlined all of these changes.
JavaScript Continues to Transform
One of the most interesting things about JavaScript is how much it continues to transform over time. It is believed that JavaScript has been and will continue to be one of the most transformational pieces of software in the industry.
There is a good chance that it will be used in ways that we haven’t even thought of yet, and it is important to keep this in mind as people continue to work to figure out what they can learn from everything that has happened to JavaScript already.
There is simply no way around the fact that many people will ultimately need to use JavaScript as a primary way to continue to program their latest inventions, and it is great news that it is still working to improve itself every day.
JavaScript Features Announced at Last Year’s Google I/O Conference
Multiple new JavaScript changes were originally revealed in the 2018 Google I/O conference but were not compatible with all browsers until now. In 2019, these functions will be 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 a map within these structures. The Symbol.iterator
key can be used to iterate through these features. The next defined
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 thenextdefined
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 executed after the promise is 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 most commonly removes 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 be not only available not only 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 the 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 creates a new array containing elements and/or arrays 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
Opinions expressed by DZone contributors are their own.
Comments