KEMBAR78
ES6 Cheatsheet | PDF
0% found this document useful (0 votes)
9 views4 pages

ES6 Cheatsheet

The ES6 Cheatsheet provides a concise overview of key features in ES6, including variable declarations with 'let' and 'const', arrow functions, template literals, and default parameters. It also covers destructuring assignment, spread and rest operators, promises, modules, classes, enhanced object literals, and data structures like Map and Set. Each feature is illustrated with simple examples for clarity.

Uploaded by

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

ES6 Cheatsheet

The ES6 Cheatsheet provides a concise overview of key features in ES6, including variable declarations with 'let' and 'const', arrow functions, template literals, and default parameters. It also covers destructuring assignment, spread and rest operators, promises, modules, classes, enhanced object literals, and data structures like Map and Set. Each feature is illustrated with simple examples for clarity.

Uploaded by

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

ES6 Cheatsheet

ES6 Cheatsheet

1. let and const

let: Block-scoped variable declaration.

const: Block-scoped constant declaration.

Example:

let a = 10;

const PI = 3.14;

2. Arrow Functions

Shorter syntax for functions.

Example:

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

3. Template Literals

Multiline strings and string interpolation.

Example:

const name = "John";

const message = `Hello, ${name}!`;

4. Default Parameters

Default values for function parameters.

Page 1
ES6 Cheatsheet

Example:

function greet(name = 'Guest') {

return `Hello, ${name}`;

5. Destructuring Assignment

Extract values from arrays or properties from objects.

Example:

const [a, b] = [1, 2];

const {name, age} = {name: "John", age: 30};

6. Spread and Rest Operators

Spread: Expand array or object.

Rest: Condense remaining arguments into an array.

Example:

const arr = [1, 2, 3];

const newArr = [...arr, 4];

function sum(...nums) {

return nums.reduce((a, b) => a + b);

7. Promises

Handle asynchronous operations.

Page 2
ES6 Cheatsheet

Example:

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

if (true) resolve("Success");

else reject("Failure");

});

8. Modules

Export and import code across files.

Example:

// export.js

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

// import.js

import { add } from './export.js';

9. Classes

Syntax for object-oriented programming.

Example:

class Person {

constructor(name) {

this.name = name;

greet() {

return `Hello, ${this.name}`;

Page 3
ES6 Cheatsheet

10. Enhanced Object Literals

Shorter syntax for object methods and properties.

Example:

const name = "John";

const obj = { name, greet() { return `Hi, ${name}`; } };

11. Map and Set

Map: Key-value pairs.

Set: Unique values.

Example:

const map = new Map();

map.set('key', 'value');

const set = new Set([1, 2, 2, 3]); // {1, 2, 3}

Page 4

You might also like