[go: up one dir, main page]

0% found this document useful (0 votes)
7 views5 pages

New DOCX Document

ES6, or ECMAScript 2015, is a major update to JavaScript that enhances its efficiency and readability with features like block-scoped variables, arrow functions, template literals, destructuring assignment, default parameters, classes, modules, and promises. These features improve code organization and handling of asynchronous operations. ES6 is now widely supported in modern browsers and development environments.

Uploaded by

Supriya Nevewani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

New DOCX Document

ES6, or ECMAScript 2015, is a major update to JavaScript that enhances its efficiency and readability with features like block-scoped variables, arrow functions, template literals, destructuring assignment, default parameters, classes, modules, and promises. These features improve code organization and handling of asynchronous operations. ES6 is now widely supported in modern browsers and development environments.

Uploaded by

Supriya Nevewani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Introduction to ES6 (ECMAScript 2015)

ES6, officially known as ECMAScript 2015, is a significant update


to the JavaScript language specification. It introduced many
new features that make writing JavaScript more efficient,
readable, and powerful. ES6 is now widely supported across
modern browsers and development environments.
Important Features of ES6

let and const:


Before ES6, var was used to declare variables, which has
function scope and can lead to unexpected behaviors.

let allows block-scoped variables, meaning the variable is only


accessible within the block it is defined.

const declares constants whose values cannot be reassigned.

js

let count = 10;const PI = 3.14;

Arrow Functions:
Arrow functions provide a shorter syntax for writing functions.
They also lexically bind the this keyword, avoiding issues with
traditional function scope.

js
const add = (a, b) => a + b;

Template Literals:
Template literals use backticks (`) to create strings and allow
embedding expressions inside strings using ${}.

js

const name = "John";console.log(`Hello, ${name}! Welcome to


ES6.`);

Destructuring Assignment:
Destructuring makes it easy to extract values from arrays or
properties from objects into individual variables.

js

const [x, y] = [5, 10];const {firstName, lastName} = {firstName:


'Jane', lastName: 'Doe'};
Default Parameters:
Functions can have default values for parameters, which are
used if no value or undefined is passed.

js

function greet(name = 'Guest') {


console.log(`Hello, ${name}`);
}greet(); // Hello, Guest

Classes:
ES6 introduced the class syntax as a cleaner way to create
objects and handle inheritance, though it is syntactical sugar
over JavaScript’s prototype-based inheritance.

js

class Person {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hi, I am ${this.name}`);
}
}

Modules:
ES6 modules allow you to import and export pieces of code
between different files, promoting better code organization.

js

// export.jsexport const pi = 3.14;


// import.jsimport { pi } from './export.js';

Promises:
Promises provide a cleaner way to handle asynchronous
operations compared to traditional callbacks, improving code
readability and error handling.

let promise = new Promise((resolve, reject) => {


setTimeout(() => resolve('Done'), 1000);
});
promise.then(result => console.log(result));

You might also like