In addition to its increased performance, ES6 is fully backward compatible, making it possible for developers to write code in one version of the language and run it in another. While this backward compatibility is a great benefit, there are some interesting tradeoffs as well.
It introduces classes
Classes are an essential part of object-oriented programming (OOP), a way of structuring programs that focus on the interaction between objects. With ES6, you can create classes using the class keyword, and then use them to create the objects you need. Classes have several important roles, including encapsulating data and facilitating communication between objects.
A class must have a constructor, or function, to allow you to pass values to it. It can also contain static functions, using the static keyword. Inheritance used to be complicated, but ES6 has simplified this process with the extended keyword. This allows you to create new entities from an existing class, and the new ones are called subclasses.
A class contains a description and is composed of a declaration and a definition. A class may have a few instances, but each instance is unique. Classes are the blueprint for objects, and classes can create many different objects. In ES6, classes also contain Constructors and Functions, which allocate memory for class objects and take responsibility for actions.
In ES6, an iterable is a collection of items. Its method next() returns the next item in the iterable. If there is more than one value, it evaluates to true. You can use the iterator’s private properties to encapsulate the state.
Iterators are powerful properties to have in an object. For example, you can use iterators in for-loops to avoid writing long path names. You can also consume an iterable without a built-in loop by calling next() on the iterable.
When using iterables in ES6, it is important to be aware of how they work. An iterable object has two types: an iterator and a generator. An iterator can contain multiple values, and a generator allows you to specify which of them should be returned to the next.
The rest parameter is useful in situations where you are unsure of how many parameters you need to pass into a function. By using this method, you can easily gather all the parameters and pass them into a single function. This will cut down on boilerplate code that would be needed to convert each parameter to an array.