ECMAScript 6 (ES6) enhancements to the JavaScript language

Sun Jan 1, 2023

ECMAScript 6 (also known as ES6 or ECMAScript 2015) is a version of JavaScript that introduced several new features to the language. Here are a few examples:

  • let and const: ES6 introduced two new ways to declare variables: let and const. let is similar to the var keyword, but variables declared with let are block-scoped, rather than function-scoped. const is used to declare variables that cannot be reassigned.
  • Arrow Functions: ES6 introduced a new shorthand syntax for defining functions, called arrow functions. Arrow functions have a more concise syntax and their this keyword lexically bound.

let add = (a, b) => a + b;
  • Template literals: ES6 introduced a new way to create strings that include variables, called template literals. These use backticks () instead of single or double quotes, and variables are denoted by a dollar sign and curly braces (${}`)
let name = "John"; console.log(`Hello, ${name}!`);
  • Destructuring: ES6 introduced a new destructuring feature, which allows you to extract values from arrays and objects and assign them to variables.
let [a, b, c] = [1, 2, 3];
let {x, y, z} = {x: 1, y: 2, z: 3};
  • Classes: ES6 introduced a new way to define classes, similar to those in other object-oriented languages.
class Person { constructor(name) { this.name = name; } sayHello() { console.log("Hello, my name is " + this.name); } }
  • Modules: ES6 introduced a new way to organize and reuse code, called modules. Modules allow you to define a set of exports (variables, functions, classes, etc.) that can be imported into other files.
// myModule.js export let x = 1; export function add(a, b) { return a + b; }

// main.js import {x, add} from "./myModule.js"; console.log(x); // 1 console.log(add(1, 2)); // 3

These are just a few examples; many more features are introduced in ES6, such as Promises, Symbol, Generators, etc.

DCT Academy
Full Stack web development training institute in Bangalore

Launch your GraphyLaunch your Graphy
100K+ creators trust Graphy to teach online
𝕏
Best MERN Full Stack Development Course | Bangalore | Offline | Online | 100% Placements | Training Institute | Front End Course | React JS Training | Online Course India 2024 Privacy policy Terms of use Contact us Refund policy