JavaScript is a programming language used to make web pages interactive.
It is widely supported across all modern web browsers.
console.log("Hello, world!");
- Runs in browser
- Event-driven
Variables store data values.
Use let, const, or var to declare variables.
let x = 5;
- let is block scoped
- const is constant
Functions are blocks of code designed to perform tasks.
You can define them using the function keyword.
function greet() { alert("Hi!"); }
- Reusable code
- Can take arguments
Loops repeat blocks of code.
Common types: for, while, do...while.
for (let i = 0; i < 5; i++) { console.log(i); }
- for loop
- while loop
Arrays hold multiple values in one variable.
Access elements by their index.
const fruits = ["apple", "banana"];
- Index starts at 0
- Supports many methods like push()