ECMAScript - ES6


JavaScript ES6 brings new syntax and new awesome features to make your code more modern and more readable. It allows you to write less code and do more. ES6 introduces us to many great features like arrow functions, template strings, class destruction, Modules… and more. Let’s take a look.

New Features in ES6

  • The let keyword
  • The const keyword
  • JavaScript Arrow Functions
  • JavaScript For/of
  • JavaScript Classes
  • JavaScript Promises
  • JavaScript Symbol
  • Default Parameters
  • Function Rest Parameter
  • Array.find()
  • Array.findIndex()
  • New Math Methods
  • New Number Properties
  • New Number Methods
  • New Global Methods
  • JavaScript Modules

const and let

const is a new keyword in ES6 for declaring variables. const is more powerful than var. Once used, the variable can’t be reassigned. In other words, it’s an immutable variable except when it used with objects.

This is really useful for targeting the selectors. For example, when we have a single button that fires an event, or when you want to select an HTML element in JavaScript, use const instead of var. This is because var is ‘hoisted’. It’s always preferable to use const when don’t want to reassign the variable .

Example -

Example -

Example -

Example -