JavaScript Shorthand

This reference page for JavaScript shorthand for quick and efficient coding.

1. Declaring Variables

let firstName, lastName, age = 25;

2. Ternary Operator

let status = (age >= 18) ? 'adult' : 'minor';

3. Short-Circuit Evaluation

if (input) {
    process(input);
}

4. Template Literals

let greeting = `Hello, ${firstName} ${lastName}!`;

5. Arrow Functions

const greet = name => `Hello, ${name}!`;

6. Default Parameters

function greet(name = 'Guest') {
    return `Hello, ${name}!`;
}

7. Object Property Shorthand

let person = { firstName, lastName, age };

8. Destructuring Assignment

let { firstName, lastName, age } = person;

9. Spread Operator for Arrays

let combined = [...arr1, ...arr2];

10. Spread Operator for Objects

let combined = { ...obj1, ...obj2 };