Introduction

JavaScript is a powerful, versatile scripting language used for web development.

It can be used for both frontend and backend development.

JavaScript is dynamically typed and event-driven.

It runs in the browser and on the server with Node.js.

This documentation will guide you through core JavaScript concepts.

console.log('Hello, JavaScript!');
Variables and Data Types

Variables store data in JavaScript. You can declare them with let, const, or var.

Data types include string, number, boolean, object, null, undefined, and symbol.

Use const when the value should not change.

Use let when the value may change.

Avoid using var in modern JavaScript.

let age = 30; const name = "Alice";
Functions

Functions are reusable blocks of code.

You can define them using function declarations or expressions.

Arrow functions are a concise way to write functions.

Functions can take parameters and return values.

You can also nest functions within functions.

function greet(name) { return "Hello " + name; } const add = (a, b) => a + b;
Control Structures

Control structures determine the flow of execution in code.

Use if/else for conditional execution.

Use switch for multiple branches.

Loops like for and while iterate over code blocks.

Use break and continue to control loop execution.

if (x > 0) { console.log("Positive"); } for (let i = 0; i < 5; i++) { console.log(i); }
DOM Manipulation

The DOM represents the structure of a webpage.

JavaScript can modify HTML and CSS via the DOM.

Use querySelector or getElementById to select elements.

You can change text, styles, attributes, and more.

Event listeners respond to user interactions.

document.getElementById("title").textContent = "New Title"; document.querySelector(".btn").addEventListener("click", handleClick);