JavaScript: Intro to ES6

Jonathan Wong
2 min readAug 22, 2020

You’ve probably came across the term ECMAScript 6 or ECMAScript 2015 or ES6 for short. As the name suggests, ES6 is the sixth version of the ECMA script programming language and was released in 2015. To make a long story short, it refers a new set of syntax used in JavaScript and all the new functions made available. So what makes ES6 different from the other previous versions? Let’s go over some of the new features!

Declaring Variables

In ES6, there are now two new ways to declare variables! Before ES6, you were limited to using var. Now with ES6, you can use let or const. Let’s go over the difference between each variable declaration.

let is used to declare a variable in which you plan or know the value which change over time. For example, a counter or a person’s bank account balance, a for loop. For example,

for (let i = 0; i < arr.length; i++) {
i = i + 1
}

const is short for constant, which you can imagine is used to assign a constant value to a variable. This meaning that the value will not change or be reassigned.

const example = “constantValue”

const and let are preferred over var due to var being function scoped rather than block scoped.

Arrow Functions

Arrow functions allow for a short hand syntax version of a normal function. Look below for the examples.

function example (x, y) {
return (x*y)
}
example = (x, y) => { return x * y }

Classes

ES6 introduced classes. Check my previous post to where I talk more about classes in JavaScript.

class Phone {
constructor() {
this.phonename = brand;
}
}
newPhone = new Phone(“iPhone”)

Conclusion

Please note that these are just some of the new features in ES6. Check out the link below for more information on the new features!

--

--