By Nilson Jacques

Editorial: Are You Writing ES6 JavaScript Yet?

By Nilson Jacques

This is the editorial from our latest JavaScript newsletter, you can subscribe here.

When was the last time you wrote some ES6 code? A recent developer survey called The State of JavaScript reported that 74% of respondents have already used the new syntax and intend to do so again. A further 21% have heard of it and are interested in learning. The ES2015 version of JavaScript (referred to as ES6 from here on) has been an official standard for almost a year and a half now, but it still seems like a lot of blog posts, articles, and tutorials are still being published that use the older ES5 syntax.

This past week, I spent some time working on a Chrome extension. One of the nice things about developing Chrome extensions is that the browser is fixed, and so you know what features are supported. The decision was made that the extension would be written in ES6-flavored JavaScript, which worked out well for me as I’ve recently been trying to utilize ES6 in my code whenever possible, in order to become fluent with the new syntax.


Of course, it’s not just Chrome that can run ES6 natively. Support for the new standard has come on leaps and bounds, with the latest releases of the major desktop browsers all complying with over 90% of the specification (with tail call optimization being the last major outstanding feature). The current releases of both Node 6 and 7 have similarly good levels of support. Of course, most of the time we don’t have the luxury of just coding for compliant browsers – we have to support mobile browsers (which still lag being in their support for ES6) and, naturally, older versions of IE.

Thankfully, we don’t have to give up on using modern JavaScript to support legacy engines thanks to the ability to transpile (convert the source code) to ES5-compatible code. This is sometimes mentioned as a reason against adopting ES6 at the current time, but I don’t find that a convincing argument. For a start, most real-world applications are going to be using a build step of some sort already; compiling SASS/Less, bundling modules, or, at the least, concatenating files. More significantly, it looks like transpiling will be with us for the foreseeable future. Even when the majority of users’ browsers support ES6 natively, we’ll most likely still be transpiling in order to use the latest and greatest version of the standard (ES2020, anyone?).

Uncle Sam saying 'We want you to write ES6 JavaScript'

In my opinion, switching to ES6 is worthwhile for the syntax changes alone. You may be shaking your head, but I think things such as arrow functions, object property and method shorthands, default parameters, and template strings can really help to streamline your code. “These things are just syntactic sugar,” you might say. Taking default function parameters as an example, it might only take an extra line of code to do this in ES5 but every extra line you don’t have to type makes your code more concise and more readable. You can focus on logic over boilerplate.

It goes without saying that not everyone has been thrilled with the updates to the language. Probably the most contentious issue was the introduction of the new Class syntax, which attempts to hide JavaScript’s prototypal nature behind a facade that makes it appear like more traditional object-oriented languages. Critics argue that this obscures important details of how JavaScript’s prototype inheritance actually works, while some go as far as to advocate avoiding the use of classes altogether in favor of more idiomatic techniques, such as factory functions. Personally, I think that whichever side you happen to agree with it’s not an argument to avoid the other benefits of adopting ES6 – take or leave classes as you see fit.

So, when was the last time you wrote some ES6 code? Maybe you already use it on a day-to-day basis, or perhaps you hate the new syntax and have sworn to avoid it at all costs? Should we drop ES5 here at SitePoint and start exclusively publishing content in the modern syntax? I’d love to hear your thoughts, so please leave a comment or tweet me your thoughts @sitepointjs

  • lucentminds

    Just because the syntax is newer, doesn’t mean it’s better. Reading and writing javascript has now become fragmented. It would be better to have left javascript alone and call ES6 it’s own language.

    • M S i N Lund

      I agree.

      People post all kind of gobbledygook now, claiming its java-script.

      Its like they have a roll of syntax-of the-day toilet paper or something!

    • Trhq

      But JavaScript literall is ECMAScript. If you’ve written any JavaScript in the last 20 years, you’ve been writing ECMAScript. The only reason we still call it JavaScript is because ECMAScript is a super ugly name. But the only controversy over the nomenclature of the current version of JavaScript is that the maintainers renamed it from ES6 to ES2015.

      I think it’s unfair to blame a language for the people who use it to write bad code unless the bad code is the result of the language’s shortcomings. You could definitely argue that the language of JavaScript has been responsible for a lot of bad code, and if it wasn’t a living language it would still be as terrible and ugly as it was in the 90s.

      ES6 is a great improvement and feels like a milestone in the efforts that have been made to fix all of the broken stuff that’s a hangover from the bad old days of JS, JScript, ActionScript etc.

    • Nilson Jacques

      I mention in the editorial that I believe the new syntax is better, not because it’s newer (which would be a silly argument), but because it’s more concise and allows you to drop a lot of boilerplate from your code. The less code you have to read, the better.

      Creating a separate language would be a less-than-ideal solution, as you’d have a much harder time getting it adopted by browsers (even Google eventually gave up on trying to get Dart natively supported). Releasing ES6 as a new JavaScript standard allows us to have updates to the language while maintaining backwards compatibility with pre-existing (ES5 and below) code.

    • Raivo Laanemets

      I would definitely consider let/const syntax an improvement. It communicates the intent of code more precisely (const variables won’t change). The fragmentation issue is not nice tho.

  • Raivo Laanemets

    Unfortunately async/await are not part of ES6. While still awesome, it might not be a good idea to use features in example code that require transpilers.

Get the latest in JavaScript, once a week, for free.