<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: [ATTILA]</title>
    <description>The latest articles on DEV Community by [ATTILA] (@realattila).</description>
    <link>https://dev.to/realattila</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F320097%2F262c8348-347e-417c-81dc-b5195c0487b6.png</url>
      <title>DEV Community: [ATTILA]</title>
      <link>https://dev.to/realattila</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/realattila"/>
    <language>en</language>
    <item>
      <title>The best features added to JavaScript from 2016 to 2021</title>
      <dc:creator>[ATTILA]</dc:creator>
      <pubDate>Thu, 06 Jan 2022 08:43:01 +0000</pubDate>
      <link>https://dev.to/realattila/the-best-features-added-to-javascript-from-2016-to-2021-5803</link>
      <guid>https://dev.to/realattila/the-best-features-added-to-javascript-from-2016-to-2021-5803</guid>
      <description>&lt;p&gt;hi,ECMAScript is a JavaScript standard meant to ensure the interoperability of web pages across different web browsers. It is standardized by Ecma International according to the document ECMA-262. ECMAScript is commonly used for client-side scripting on the World Wide Web.&lt;br&gt;
in this article, we gonna talk about amazing features that we all need to use in our projects.&lt;br&gt;
after ECMAScript 2015, nearly we have a new version of javascript that have major changes, like arrow functions, sets, maps, classes and destructuring.&lt;/p&gt;
&lt;h2&gt;
  
  
  ES7(ECMAScript 2016)
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Array.prototype.includes
&lt;/h3&gt;

&lt;p&gt;Determines whether an array includes a certain element or not&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 2, 3].includes(3, 0, 7); // true
[1, 2, NaN].includes(NaN); // true
[0,+1,-1].includes(42); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ES8(ECMAScript 2017)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Async functions
&lt;/h3&gt;

&lt;p&gt;here is goood example look at code blow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function foo() {
   const result1 = await new Promise((resolve) =&amp;gt; setTimeout(() =&amp;gt; resolve('1')))
   const result2 = await new Promise((resolve) =&amp;gt; setTimeout(() =&amp;gt; resolve('2')))
}
foo()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function foo() {
    try {
        const bar = await new Promise((resolve) =&amp;gt; setTimeout(() =&amp;gt;  resolve('1')));
    }
    catch(e) {
        console.log(e)
    }
}
foo()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in this example you could simply use async function to use try catch&lt;/p&gt;

&lt;h3&gt;
  
  
  Object.values
&lt;/h3&gt;

&lt;p&gt;get all the values of the object as an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var person = { fname: "Hemanth", lname: "HM", location: "Earth", type: "Human" };
Object.values(person);
// ["Hemanth","HM","Earth","Human"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ES9(ECMAScript 2018)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Object rest properties
&lt;/h3&gt;

&lt;p&gt;Rest properties for object destructuring assignment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let { fname, lname, ...rest } = { fname: "Hemanth", lname: "HM", location: "Earth", type: "Human" };
fname; //"Hemanth"
lname; //"HM"
rest; // {location: "Earth", type: "Human"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  spreat operator
&lt;/h3&gt;

&lt;p&gt;The spread operator can be used to combine multiple objects or cloning objects.&lt;br&gt;
remember: speart operator can do shallow clone not deep clone, if you do not know the difference between shallow and deep wait for my next article :D&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj1 = {a:10,b:20}
const obj2={c:30}
const clone_obj={...obj1}
const obj3 = {...obj1,...obj2}
console.log(clone_obj) // {a: 10, b: 20}
console.log(obj3) // {a: 10, b: 20, c: 30}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Promise: finally()
&lt;/h3&gt;

&lt;p&gt;finally is a new callback that always executed, no matter if then or catch is called. it is too useful for clean up state especially in reactjs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(url)
  .then()
  .catch()
  .finally(() =&amp;gt; console.log(`I'm always called!`));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ES10(ECMAScript2019)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Array.flat()
&lt;/h3&gt;

&lt;p&gt;The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. depth can pass as first param. in down example, i send number 2 for depth.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array1 = [1,2,[3,4,[5,6]]]
console.log(array1.flat(2)) // [1,2,3,4,5,6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  dynamic import
&lt;/h3&gt;

&lt;p&gt;To dynamically import a module, the import keyword may be called as a function. When used this way, it returns a promise.&lt;br&gt;
in dynamic import, you could call the module when you really need it to use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import('/modules/my-module.js')
  .then((module) =&amp;gt; {
    // Do something with the module.
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ES11(ECMAScript2020)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  optional chaining
&lt;/h3&gt;

&lt;p&gt;Optional Chaining, known to babel users, is now supported natively by Javascript. This functionality removes the need for conditionals before calling a variable or method enclosed in it. optional chaining prevent to pass Error object, if our code has an undefined value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const smartphones = {
    brands: {
        apple: true
    }
}
console.log(smartphones.companies?.motorola) // output is: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  nullish coalescing operator
&lt;/h3&gt;

&lt;p&gt;A new operator was added to Javascript. It came to cause a discrepancy between Javascript's falsey value. We use the falsey condition with the || operator. The falsey values ​​are: 0, undefined, null, false, NaN&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(null || 'not false value'); // 'not false value'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ES12 (ECMAScript2021)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  String.replaceAll()
&lt;/h3&gt;

&lt;p&gt;The replaceAll()function on the String prototype allows replacing all instances of a sub-string, without using regex.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const orgStr = 'JavaScript, often abbreviated as JS, is a programming language that conforms to the ECMAScript specification. JavaScript is high-level, often just-in-time compiled and multi-paradigm.';
let newStr2 = orgStr.replaceAll('JavaScript', 'TypeScript');
console.log(newStr2); // 'TypeScript, often abbreviated as JS, is a programming language that conforms to the ECMAScript specification. TypeScript is high-level, often just-in-time compiled and multi-paradigm.'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;thank you for reading the article, I will be glad if you write a comment. if you know other features that are useful for you and I forget to write, you can write in comments for me and other readers.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>react</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
