ES6 Advancements: arrow functions and const/let variables

ES6 was released in June of 2015. With it came many new features such as arrow functions, let and const, promises, modules, and classes. There are many more but these are the most widely adopted according to a survey done by 2ality.com. All of these things technically existed in Javascript before ES6 was implemented but the new release made them easier to write and read, something called “syntactic sugar.” This article will be mostly about arrow functions but we will also touch on the difference between const, let and why var has been thrown by the wayside.

Arrow Functions

Invoking the arrow function, sometimes referred to as fat arrows, relieves developers from having to type “function” with each invocation. Below is a simple example of how the function syntax changes going from traditional functions to an arrow.

Traditional function expression
Example of an arrow function

Binding of “this”

Using arrow functions to manipulate datasets

Note that curly braces are only necessary when enclosing multiple statements inside the same function. A similar example could be written in this manner.

Const/Let variables

Let

Here we see that we can modify a let variable
In this example, we see that we can’t re-declare a let variable

We use let instead of const when we know the variable will be modified, or at least have the ability to be modified, at some point in our code. The opposite is true for const declarations of variables, along with a couple of other rules.

Const

Hoisting