0% found this document useful (0 votes)
3 views2 pages

ES6 Features Explained with Examples

The document provides an overview of key features in ES6, including Template Literals for embedding expressions, Enhanced Object Literals for shorthand properties, and Default Parameters for function arguments. It also covers Classes and Inheritance, Promises for handling asynchronous operations, Symbols and Iterators for unique keys, Sets and Maps for unique values and key-value pairs, and Generators for pausing and resuming function execution. Each feature is accompanied by a concise example demonstrating its usage.

Uploaded by

maithiliwagh1987
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)
3 views2 pages

ES6 Features Explained with Examples

The document provides an overview of key features in ES6, including Template Literals for embedding expressions, Enhanced Object Literals for shorthand properties, and Default Parameters for function arguments. It also covers Classes and Inheritance, Promises for handling asynchronous operations, Symbols and Iterators for unique keys, Sets and Maps for unique values and key-value pairs, and Generators for pausing and resuming function execution. Each feature is accompanied by a concise example demonstrating its usage.

Uploaded by

maithiliwagh1987
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

ES6 Deep Dive

1. Template Literals
Feature: Embed expressions and multiline strings using backticks
Example:
const name = "Bob";
const msg = `Hello, ${name}!`;
[Link](msg);

2. Enhanced Object Literals


Feature: Shorthand properties, methods, computed keys
Example:
const age = 30;
const person = { age, greet() { return `Hi`; }, ["isAdult"]: true };

3. Default Parameters
Feature: Provide default values for function arguments
Example:
function greet(name = "Guest") { return `Hello, ${name}`; }
[Link](greet());

4. Classes and Inheritance


Feature: Define classes and extend them
Example:
class Animal { speak() { return "noise"; } }
class Dog extends Animal { speak() { return "bark"; } }
[Link](new Dog().speak());

5. Promises
Feature: Handle async operations with then/catch
Example:
new Promise(res => res("Done"))
.then(msg => [Link](msg));

6. Symbols & Iterators


Feature: Unique keys and iterable protocol
Example:
const id = Symbol("id");
const obj = { [id]: 123 };
[Link](obj[id]);

7. Sets & Maps


Feature: Unique values (Set), key-value pairs (Map)
Example:
const s = new Set([1,2,2]); [Link]([Link]);
const m = new Map(); [Link]("key","val"); [Link]([Link]("key"));
8. Generators
Feature: Pause/resume function execution with yield
Example:
function* gen() { yield 1; yield 2; }
[Link](gen().next());

You might also like