Modern JavaScript is often defined as ES6 (from 2015) or newer.
Legacy JavaScript is considered ES5 (from 2009). Older versions are obsolete.
95% of browser traffic supports:
- Classes:
class - Arrow functions:
=> - Generators:
function*/yield* - Block scoping:
const/let - object shorthand:
{a, b, c} async/await
94% of browser traffic supports:
For the remaining 6% of traffic that doesn't support modern JS, we can transpile modern JS into older JS, at a cost to both bandwidth and execution speed of 6x or more.
- 95% of web traffic comes from browsers that support ES2017.
- 70% of web traffic comes from browsers that support ES2021.
The exports field in a
package.json file was first supported in Node v12.8, which support ES2019
syntax.
{
"name": "foo",
"exports": "./foo.js",
}{
"name": "foo",
"exports": "./foo.js",
"main": "./foo-es5.js",
}For the 95% of browser traffic that supports ES8 from 2017, use:
<script type="module" src="app.modern.js"></script>For the 5% of browser traffic that supports ES5 from 2009, use:
<script nomodule src="app.legacy.js"></script>- ES1: June 1997
- ES2: June 1998
- ES3: December 1999
- ES4: June 2003 (abandoned)
- ES5: December 2009
- ES5.1: June 2011
- ES6: June 2015
- ES7: June 2016
- ES8: June 2017
- ES9: June 2018
- ES10: June 2019
- Google Chrome Developers: Transitioning to modern JavaScript
- Wikipedia: ECMAScript
- EStimator analyzes how modernizing a site's JS can save bandwidth