JavaScript Guide

Introduction

JavaScript is a versatile, high‑level programming language that powers interactive behavior on the web. This guide covers fundamentals, modern features, and hands‑on examples.

Table of Contents

Basics

Declare variables using let, const, or var. Use === for strict equality.

let message = "Hello, World!";
if (message === "Hello, World!") {
    console.log(message);
}

Functions

Arrow functions provide a concise syntax:

const add = (a, b) => a + b;
console.log(add(2, 3)); // 5

DOM Manipulation

Interact with page elements via document.querySelector and event listeners.

document.querySelector('#myBtn').addEventListener('click', () => {
    alert('Button clicked!');
});

Async / Await

Handle asynchronous operations cleanly with async functions.

async function fetchData() {
    const response = await fetch('https://api.example.com/data');
    const data = await response.json();
    console.log(data);
}
fetchData();

Playground

Write JavaScript code below and see the result instantly.