10 Reasons We Love JavaScript’s ES2015

January 18, 2016
Digital Surgeons

JavaScript has grown up over the last few years from a teenager of scripting languages with flaws and quirks that we love to hate, into a much more mature programming language powering some of the most sophisticated applications on the planet. Bless, how they grow up fast. With the release of ES6, (or ES2015 as the new versions will affectionately be named after the year of their release) JavaScript has seen huge improvements — improvements that we at Digital Surgeons are beyond excited about. Here’s just 10 of our favorite features that push JavaScript into the modern age of web development.

1. Classes

It’s been a long time coming! Despite functional design patterns gaining massive popularity for very valid reasons, classes are still an integral concept of a mature programming language. Although simply syntactic sugar over the prototypal inheritance we all know and love, JavaScript is a highly object oriented language and this was a much needed next step. Along with class syntactic sugar we get constructors, getters and setters, static members, super calls, and sub-classing.

Learn more about Classes

2. Modules

For years now JavaScript developers have been working on systems that allow us to write the modular code required to build complex applications at scale. Systems like CommonJS and AMD have become common place in the modern development environment and JavaScript developers can finally rejoice in a native implementation. The ES6 module system has a very compact syntax and supports asynchronous and configurable module loading, a system that CommonJS and AMD fans alike will love.

Learn more about Modules

3. Promises

Over recent times, Promises have risen to the top of the design pattern food chain with many developers utilizing libraries like Q, When, RSVP, and other Promise implementations. Ridding us of nested callback hell, Promises allow us to write readable asynchronous code that’s easy to work with. With ES2015, promises are baked in, including all the features we’ve grown to love in the earlier implementations. If you are new to Promises, now is the time to get involved.

Learn more about Promises

4. Arrow Functions

Arrow functions not only provide a shorthand method for writing anonymous functions, they also provide lexical scoping inheriting from their parent. JavaScript developers no longer need to hack around the issue of passing scope between contexts with bind() and apply() or this = that, instead we can use an arrow function as a callback and gleefully access the goodies of the parent function.

Learn more about Arrow Functions

5. Block Scoping

JavaScript has always had an (often confusing) function-level scope, tripping up beginners and inflicting hacky pain on experienced developers throughout the industry. The let statement declares a block scope local variable and allows developers greater control over the flow of a program offering respite from hoisting side effects. Put simply, a let variable declared inside of an if statement is not accessible from the outside. Ah, sanity.

Learn more about Block Scoping

6. Template Strings

Building HTML with regular string concatenation is a nightmare with JavaScript and sadly an essential in a language that constantly interacts with the DOM. Developers have been trying to fix this problem for years with fully fledged templating systems like Mustache, Handlebars, EJS, and others. Finally, using the new backtick operator, JavaScript developers can create template strings using variables natively in the language. String interpolation and multi line strings ftw!

Learn more about Template Strings

7. Iterators

We have an exciting new feature to play with in the form of iterators — a brand new concept in JavaScript that allows us to define sequences at the language level. Put simply, we can define exactly how objects are iterated through; a custom for-loop if you will. Iterators can be executed using the new for-of syntax and allow us granular control over how an object is consumed. This is a huge topic with many new concepts including the new Symbol property (far too much information for this article). However, we are super excited by them and highly recommend diving in head first.

Learn more about Iterators

8. Generators

Generators bring a different type of function to traditional JavaScript. They may be paused in the middle, one or many times, and resumed later, allowing other code to run during these paused periods. Using the new yield keyword, generators can pause themselves from the inside. However, once paused they must wait for instruction from the outside to continue once again. This is handled with generator iterators — a mouthful indeed! Similarly to regular iterators, generators can be resumed and run to the next pause step using the next() method and, just like iterators, generators are a huge topic far too large to discuss in full here. Dive in, and explore the world of *functions().

Learn more about Generators

9. Parameters

ES2015 pimped JavaScript parameters with a number of new features. Ending despair and disbelief for developers the world over, JavaScript now has default parameter values! Such a simple feature for such a widely adopted language to be missing, but gone are the days of default value hacks. We also have a couple of extra goodies in the form of the rest parameter and spread operator. Rest parameters allow us to represent an indefinite number of arguments as an array, e.g myFunc(a, b, …c) { }, while the spread operator allows an expression to be expanded in places where multiple arguments are expected.

Learn more about parameters

10. String / Math Functions

We are also gifted a number of simple, yet super useful String and Math methods that make working with strings and numbers easier than before. I know, not hard right?!. String offerings like includes(), startsWith(), endsWith(), and repeats() means less hacks for us all. There’s a lot more fun to be had with numbers too, including specifying integers in binary and octal notation as well as several new methods for us to play with including sign(), trunc() and cbrt().

Learn more about String / Math functions

Forward Obsessed...

ES2015 brings a wealth of new features to our favorite and often strange little language. Every time you use a new feature instead of that same old ugly hack you get a feeling of joy that only technologists can understand. There is so much more than we have covered here so dive in and see how the language has grown up and transformed.

But it doesn’t end there, ES2016 is on its way with some seriously amazing features to bring to the table. Including object.observe and the highly anticipated async await. With the evolution of the “Internet of Things” and JavaScript’s subsequent diversification, we couldn't be more excited for the future. As JavaScript developers, our language is maturing, our environment is expanding, and our apps have the potential to move from the traditional desktop browser to users' pockets, wrists, homes, and cars. 

Here's to the future...

Thanks for reading.
Digital Surgeons
Spread the word!