What is JavaScript?
JavaScript is the programming language of the web. Every modern browser can run it, which makes it the only language that works on every phone, laptop and tablet without installing anything. Today it also runs on servers (Node.js), in mobile apps, in desktop apps, and even on tiny devices.
What you'll learn in this lesson
- What a program is and how JavaScript runs it
- How to print output with
console.log - How to use the live code editors on this site
Your first program
A program is a list of instructions that the computer carries out from top to bottom. Below is a real JavaScript program. Press ▶ Run to run it.
console.log(...) prints whatever you put between the brackets. The text in quotes is called a string — a piece of text.
Tip: Every code box on this site is editable. Change the text, then press Run again (or press Ctrl + Enter, or ⌘ + Enter on a Mac). If you break something, press Reset.
JavaScript can do maths
You don't need quotes for numbers. JavaScript calculates the result before printing it.
Notice the last line: you can print several things at once by separating them with commas.
Comments
Lines that start with // are comments. JavaScript ignores them; they are notes for humans.
Errors are normal
Every programmer sees errors all day. An error message tells you what went wrong and usually where. Run this and read the message:
ReferenceError: consol is not defined means JavaScript doesn't know anything called consol. Fix the typo and run it again.
Where JavaScript runs
| Place | What it's used for |
|---|---|
| Browser | Interactive websites (buttons, forms, animations) |
| Node.js | Web servers, APIs, command-line tools |
| React Native | Mobile apps for iOS and Android |
| Electron | Desktop apps like VS Code and Slack |
Practice
Edit the program below so it prints your name, your city, and the result of 365 * 24 (how many hours are in a year).
1.What does console.log('5 + 5') print?
2.Which line is a comment?