JavaScript Basics
JavaScript brings your pages to life. It runs in the browser and can change anything on the page after it loads.
Variables with let and const
Variables store values. Use const for values that never change and let for ones that do.
const title = "hackweb.dev";
let score = 0;
score = score + 10;
console.log(title, score);
Values and types
JavaScript has a few core types — numbers, strings, booleans, and more.
const age = 25; // number
const name = "Ada"; // string
const isAdmin = true; // boolean
console.log(typeof age, typeof name, typeof isAdmin);
Strings
Strings are text. Join them with + or with template literals.
const first = "Ada";
const last = "Lovelace";
const full = `${first} ${last}`;
console.log(full);
console.log
console.log prints values to the console — your best debugging friend.
console.log("hello from the console");
The event loop
JavaScript handles one thing at a time, but things like timers happen in the background. The event loop is how they come back. Watch it in action:
name="event-loop"