[go: up one dir, main page]

0% found this document useful (0 votes)
2 views4 pages

ES6_Modern_JS_Features

The document outlines key features of ES6+ and modern JavaScript, including 'let' and 'const' for variable declaration, arrow functions for concise syntax, and destructuring for unpacking values. It also covers the spread and rest operators, template literals, default parameters, enhanced object literals, promises for asynchronous operations, classes for cleaner syntax, and modules for code reuse. Each feature is accompanied by examples to illustrate its usage.

Uploaded by

cosmaskibet444
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)
2 views4 pages

ES6_Modern_JS_Features

The document outlines key features of ES6+ and modern JavaScript, including 'let' and 'const' for variable declaration, arrow functions for concise syntax, and destructuring for unpacking values. It also covers the spread and rest operators, template literals, default parameters, enhanced object literals, promises for asynchronous operations, classes for cleaner syntax, and modules for code reuse. Each feature is accompanied by examples to illustrate its usage.

Uploaded by

cosmaskibet444
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+ and Modern JavaScript Features

1. let & const:

- 'let' allows you to declare variables that are limited in scope to the block.

- 'const' is used to declare constants (variables that cannot be reassigned).

2. Arrow Functions (=>):

- Shorter syntax for writing functions.

- Lexically binds 'this'.

Example:

const greet = name => console.log("Hello", name);

3. Destructuring:

- Allows unpacking values from arrays or properties from objects.

Example:

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

const {name, age} = {name: "Cosmas", age: 19};

4. Spread Operator (...):

- Expands arrays or objects into individual elements.

Example:

const arr = [1, 2];

const newArr = [...arr, 3]; // [1, 2, 3]


5. Rest Operator (...):

- Collects multiple elements into a single array.

- Used in function arguments and destructuring.

Example:

function sum(...nums) { return nums.reduce((a, b) => a + b); }

6. Template Literals:

- Use backticks ` for multi-line strings and embedding expressions.

Example:

const name = "Cosmas";

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

7. Default Parameters:

- Assign default values to function parameters.

Example:

function greet(name = "Guest") { console.log("Hello", name); }

8. Enhanced Object Literals:

- Easier syntax for defining objects.

Example:

const name = "Cosmas";

const user = { name, greet() { return "Hi"; } };


9. Promises:

- Handle asynchronous operations.

Example:

fetch(url)

.then(res => res.json())

.then(data => console.log(data))

.catch(err => console.error(err));

10. Classes:

- Cleaner syntax for constructor functions and inheritance.

Example:

class Person {

constructor(name) {

this.name = name;

greet() {

return `Hi, I'm ${this.name}`;

11. Modules (import/export):

- Reuse code by exporting and importing in separate files.

Example:
// file1.js

export const greet = () => "Hello";

// file2.js

import { greet } from './file1.js';

You might also like