Bab 6: Modern JavaScript (ES6+)

Bab 6: Modern JavaScript (ES6+)

6.1 Arrow Functions

6.1.1 Basic Syntax

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

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

// Arrow function with block
const calculate = (a, b) => {
    const result = a * b;
    return result;
};

// Single parameter (parentheses optional)
const square = x => x * x;

// No parameters
const sayHello = () => 'Hello!';

// Returning object literals
const createUser = (name, age) => ({ name, age });

6.1.2 Lexical This

6.2 Template Literals

6.2.1 Basic Usage

6.3 Destructuring

6.3.1 Array Destructuring

6.3.2 Object Destructuring

6.4 Spread dan Rest Operator

6.4.1 Spread Operator

6.4.2 Rest Parameter

6.5 Modules

6.5.1 Module Syntax

6.6 Map dan Set

6.6.1 Map

6.6.2 Set

6.7 Optional Chaining dan Nullish Coalescing

6.7.1 Optional Chaining

6.7.2 Nullish Coalescing

6.8 Modern Features dan Syntax

6.8.1 Object Methods

6.9 Praktik dan Latihan

6.9.1 Modern Code Refactoring

6.10 Best Practices

  • When to use arrow functions vs regular functions

  • Module organization and structure

  • Destructuring patterns

  • Performance considerations

  • Modern syntax adoption strategies

6.11 Ringkasan

  • Modern JavaScript features and syntax

  • ES6+ enhancements

  • Code organization and structure

  • Best practices and patterns

6.12 Latihan Akhir Bab

  1. Refactor legacy code using modern syntax

  2. Implement a module system

  3. Create a data processing utility using modern features

  4. Build a configuration system using modern patterns

  5. Implement a caching system using Map/Set

Last updated

Was this helpful?