ES6 Features

Arrow Functions:

Arrow functions provide a concise syntax for writing functions. They don't have their own this and arguments and are especially useful for short, one-liner functions.

                                      
                                        // Traditional function
function add(a, b) {
    return a + b;
}

// Arrow function
const addArrow = (a, b) => a + b;

console.log(add(5, 3));      // Output: 8
console.log(addArrow(5, 3)); // Output: 8
                                      
                                    

Template Literals:

Template literals allow you to embed expressions inside string literals, making string manipulation more readable.

                                      
                                        const name = "John";
const greeting = `Hello, ${name}!`;

console.log(greeting);  // Output: Hello, John!
                                      
                                    

Destructuring:

Destructuring allows you to extract values from arrays or properties from objects into distinct variables.

                                      
                                        // Destructuring an array
const numbers = [1, 2, 3];
const [first, second, third] = numbers;

console.log(first);  // Output: 1
console.log(second); // Output: 2

// Destructuring an object
const person = { name: "Alice", age: 25 };
const { name, age } = person;

console.log(name); // Output: Alice
console.log(age);  // Output: 25
                                      
                                    

let and const:

let is used to declare variables whose values can be reassigned. const is used for constants whose values cannot be reassigned.

                                          
                                            let count = 0;
count = 1;  // Valid

const pi = 3.14;
// pi = 3.14159;  // Error: Assignment to a constant variable                                            
                                          
                                        

Classes:

ES6 introduced class syntax, allowing for a more convenient way to create constructor functions and prototype-based inheritance.

                                          
                                            class Animal {
                                                constructor(name) {
                                                    this.name = name;
                                                }
                                            
                                                speak() {
                                                    console.log(`${this.name} makes a sound`);
                                                }
                                            }
                                            
                                            class Dog extends Animal {
                                                speak() {
                                                    console.log(`${this.name} barks`);
                                                }
                                            }
                                            
                                            const dog = new Dog("Buddy");
                                            dog.speak();  // Output: Buddy barks                                                                                                                                    
                                          
                                        

Modules:

ES6 introduced a standardized way to organize code into reusable and maintainable modules.

                                          
                                            // math.js (module)
export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;

// main.js
import { add, subtract } from './math';

console.log(add(5, 3));       // Output: 8
console.log(subtract(5, 3));  // Output: 2                                                                                                                                   
                                          
                                        

Modules allow you to encapsulate functionality and import/export pieces of code between files.

Hey there! Let's go for Learn fasta then! It is more than just coding; it is to have the superpower that can solve any problem. Through simple and easy-to-grasp examples you will sail through the learning process. In addition, it is not just about coding– you will acquire competencies on how to solve complex problems, analyze data, and come up with efficient solutions. Shall we start this wonderful journey together! learnfasta.com terms of use, Copyright 2025 All Rights Reserved.