JavaScript is a programming language used to create interactive effects within web browsers.
It is one of the core technologies of the World Wide Web.
console.log("Hello, world!");
JavaScript code can be embedded directly into HTML pages.
- Runs in the browser
- Lightweight
- Interpreted
Variables are used to store data values.
You can declare variables using var, let, or const.
let x = 10;
const y = 5;
Use `let` for variables that will change, `const` for ones that won’t.
- var is function-scoped
- let and const are block-scoped
Functions are blocks of code that perform a particular task.
They are executed when called or invoked.
function greet() { console.log("Hello!"); }
You can pass parameters to functions for dynamic behavior.
- Reusable
- Encapsulate logic
Loops are used to run a block of code repeatedly.
Common types include for, while, and do...while.
for (let i = 0; i < 5; i++) { console.log(i); }
while (condition) { /* code */ }
Loops help automate repetitive tasks.
- for loop
- while loop
- do...while loop
Arrays store multiple values in a single variable.
They can hold elements of any type.
let fruits = ["apple", "banana", "cherry"];
JavaScript provides many built-in methods for arrays.
- push()
- pop()
- map()