11 Amazing New JavaScript Features in ES13

<p><em>This blog post is available as a convenient and portable e-book that you can take with you anywhere.&nbsp;</em><a href="https://cbdev.link/900477" rel="noopener ugc nofollow" target="_blank"><em>Click here to get a copy</em></a><em>.</em></p> <p>Like a lot of other programming languages, JavaScript is constantly evolving. Every year, the language is made more powerful with new capabilities that let developers write more expressive and concise code.</p> <p>Let&rsquo;s explore the most recent features added in ECMAScript 2022 (ES13), and see examples of their usage to understand them better.</p> <h1>1. Class Field Declarations</h1> <p>Before ES13, class fields could only be declared in the constructor. Unlike in many other languages, we could not declare or define them in the outermost scope of the class.</p> <pre> class Car { constructor() { this.color = &#39;blue&#39;; this.age = 2; } }const car = new Car(); console.log(car.color); // blue console.log(car.age); // 2</pre> <p>ES13 removes this limitation. Now we can write code like this:</p> <pre> class Car { color = &#39;blue&#39;; age = 2; }const car = new Car(); console.log(car.color); // blue console.log(car.age); // 2</pre> <h1>2. Private Methods and Fields</h1> <p>Previously, it was not possible to declare private members in a class. A member was traditionally prefixed with an underscore (<code>_</code>) to indicate that it was meant to be private, but it could still be accessed and modified from outside the class.</p> <p><a href="https://medium.com/coding-beauty/es13-javascript-features-eed7ed2f1497">Website</a></p>