JavaScript Reference

Overview

JavaScript is a scripting language used to add interactivity to HTML documents.

Built-in Objects

Array

const arr = [1, 2, 3];
console.log(arr); // Output: [1, 2, 3]
        

Date

const now = new Date();
console.log(now); // Output: Wednesday, November 26, 2023 12:00:00 PM EST
        

Math

console.log(Math.sqrt(25)); // Output: 5
console.log(Math.max(5, 10, 3)); // Output: 10
        

Events

JavaScript provides event handlers for various types of events, including:

Calls and Returns

JavaScript uses function calls and returns to execute code sequentially.

function greet(name) {
    return `Hello, ${name}!`;
}
console.log(greet("Alice")); // Output: Hello, Alice!
        

Async/Await

JavaScript supports asynchronous programming using async/await syntax.

async function fetchData() {
    try {
        const result = await fetch("/data");
        console.log(result);
    } catch (error) {
        console.error(error);
    }
}

fetchData(); // Output: Data from API
        

Conclusion

JavaScript is a powerful language for creating dynamic web applications and enhancing user interaction.