JavaScript Basics · Lesson 1 of 6

What JavaScript is, and your zero-install setup

Understand where JavaScript runs, what it does that HTML cannot, and write your first lines in the browser console.

Data This lesson: 122KB

Every interactive thing a web page does — a menu opening, a form complaining about a wrong phone number, prices updating without a reload — is JavaScript. HTML is the page's structure and CSS its appearance (the web-development-basics course covers both); JavaScript is its behaviour. It is the only programming language browsers run, which makes it the most widely deployed language on earth and the core of the MERN stack that Lahore and Karachi software houses hire juniors into.

Your development environment is already installed: every browser contains a JavaScript engine and a console to type into. Open any page, press F12, choose Console — that panel runs JavaScript live. Type 2 + 2 and press Enter. Type "Assalam" + " o Alaikum" and see text joining. That console is where this course lives for two lessons, because instant feedback is the fastest teacher.

A program is a list of instructions executed top to bottom. Three instructions to start. console.log("hello") prints a value — the programmer's torchlight, used constantly to see what the code is doing. let price = 4500 creates a variable — a named box holding a value that can change later (price = 5000 updates it). And alert("Order saved") pops up a browser message — crude, but proof your code touched the page.

Values come in types, and three carry most programs: numbers (4500), strings (text in quotes — "Lahore"), and booleans (true/false — the raw material of decisions, next lesson). typeof tells you what you are holding: typeof 4500 is "number". Mixing types causes classic surprises — "5" + 3 is "53", because a string plus anything glues text — and meeting that surprise deliberately now, in the console, is cheaper than meeting it in a client's checkout code later.

Try it yourself

Open the console (F12) and: create variables for your name, city and a fee amount; print a sentence combining them with console.log; try "5" + 3 and 5 + 3 and explain the difference to yourself out loud; use typeof on all three variables. Ten minutes of typing — do not skip the typing.

Check what you learned

Create your free BvLogic ID to take the quiz and record your score.

Create your BvLogic ID
Continue to lesson 2 All lessons