Sitemap
Better Programming

Advice for programmers.

Do We Still Need to Compile ES6 JavaScript Code Into ES5 in 2022?

5 min readJan 9, 2022

--

Press enter or click to view image in full size

In order to be compatible with old browsers, especially the IE series, we often need to use compiling tools such as Bable to compile our ES6+ code into ES5- code.

But ES6 was released in 2015, it’s been 7 years now, do we still need to convert it into ES5? Can we use ES6 directly?

According to Can I Use, 94.06% of users’ browsers already fully support ES6.

Press enter or click to view image in full size

In addition to considering browser support, we also need to consider performance. Let’s compare the original code and compiled code from the perspective of their V8 bytecode.

1. Copy an Array

From ES6, we can use the spread operator to copy an array:

const array1 = [1, 2, 3];let a2 = [...array1];

If it was compiled to ES5 by Babel, it would use the concat function to copy an array:

var array1 = [1, 2, 3];var a2 = [].concat(array1);

--

--

No responses yet