JavaScript is a programming language that powers the web.
It is widely used for building interactive websites and applications.
You can run JavaScript directly in your browser.
console.log("Hello World!");
- Client-side scripting
- Lightweight
- Prototype-based
Variables store data values.
In JavaScript, you can use var
, let
, or const
.
let name = "Tino";
const PI = 3.14;
- let → block scope
- const → cannot be reassigned
Functions are reusable blocks of code.
You can define a function using the function
keyword.
function greet() { return "Hello"; }
Arrow functions provide a shorter syntax.
const greet = () => "Hello";
- Reusable
- Modular
- Scalable
Loops allow you to run code multiple times.
The most common loops are for
and while
.
for (let i=0; i<5; i++) { console.log(i); }
while (x < 10) { x++; }
- for loop
- while loop
- do...while loop
Arrays hold multiple values in one variable.
They are ordered collections that can be iterated.
let nums = [1,2,3,4];
nums.push(5);
console.log(nums.length);
- push()
- pop()
- map()
- filter()