VOOZH about

URL: https://www.geeksforgeeks.org/javascript/introduction-to-es6/

⇱ Introduction to ES6 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Introduction to ES6

Last Updated : 11 Jun, 2026

ES6, or ECMAScript 2015, is the 6th version of the ECMAScript programming language. ECMAScript is the standardization of JavaScript, which was released in 2015 and subsequently renamed as ECMAScript 2015.

New Features in ES6

1. The let Keyword

The let variables are mutable, i.e., their values can be changed. It works similarly to the var keyword with some key differences, like scoping, which makes it a better option when compared to var.

It prevents variable leakage outside of the intended scope.

2. The const Keyword

const is used to declare variables with a constant value, ensuring the value cannot be reassigned.

Ideal for declaring configuration constants or fixed values.

3. Arrow Functions

Arrow functions provide a concise syntax for writing function expressions and automatically bind this to the surrounding context.

  • Implicit return for single-expression functions.
  • Do not have their own 'this' context.

4. Destructuring Assignment

Destructing in JavaScript basically means the breaking down of a complex structure(Objects or arrays) into simpler parts

Object Destructuring

Array Destructuring

5. The Spread (...) Operator

The spread operator expands an array or object into individual elements or properties.

6. The For/Of Loop

The for/of loop allows you to iterate over iterable objects like arrays, strings, Maps, and Sets but in a short syntax as compared to other loops.

Iterating Over an Array

Iterating Over a String

7. Maps and Sets

Map:Maps store key-value pairs where keys can be any data type.

Set: Sets store unique values of any type.


Output
Set(3) { 1, 2, 3 }

8. Classes

ES6 introduced classes in JavaScript. Classes in javascript can be used to create new Objects with the help of a constructor, each class can only have one constructor inside it.

  • class Animal {}: Defines a simple class named Animal.
  • speak(): A method inside the class that logs a message to the console.
  • new Animal(): Creates an object dog from the Animal class.
  • dog.speak(): Calls the speak method on the dog object.

9. Promises

Promises simplify handling asynchronous operations by providing .then and .catch methods.

10. Default Parameters

Allows functions to have default values for parameters.

Additional Enhancements

  • includes(): Check if a string contains a substring.
  • startsWith(): Check if a string starts with a substring.
  • endsWith(): Check if a string ends with a substring.
  • find(): Locate the first element matching a condition.
  • findIndex(): Locate the index of the first element matching a condition.
  • from(): Convert an iterable or array-like object into an array.
  • Template Literals: Simplify string concatenation and allow embedded expressions.
  • Modules: Introduce import and export for better modularity.
  • Rest Parameters (...args): Allow functions to accept an indefinite number of arguments as an array.
  • Generators and Iterators: Enable custom iteration logic with function* and yield.
  • Binary and Octal Literals: Simplify working with binary (0b) and octal (0o) numbers.
  • Enhanced Object Literals: Provide shorthand for methods, properties, and dynamic keys.
  • WeakMap andWeakSet: Store weakly-referenced objects for specialized use cases.
  • Proxy and Reflect: Add interception capabilities and reflection utilities for objects.
  • Symbol: Introduces unique, immutable primitive data types useful for property keys.
  • Block-scoped Functions: Functions declared inside blocks respect block scope.
Comment
Article Tags: