In this lesson you will
- Run JavaScript in a page and read its output in the console
- Choose between const and let, and explain why var is avoided
- Work with strings, numbers and booleans, and build text with template literals
- Handle decimal money values without surprise rounding errors
Where JavaScript runs and how to see its output
JavaScript is the only programming language every web browser runs. You add it to a page with a <script> element, usually just before </body> or in a separate file linked with <script src="app.js" defer></script>. The browser reads the code from top to bottom and runs each statement in order. JavaScript also runs outside browsers, for example in Node.js on servers, but this course starts in the browser because you already have one.
console.log() prints a value to the console, a panel for developers. In your own browser, open the developer tools (F12, or Ctrl+Shift+I, or Cmd+Option+I on a Mac) and choose Console. On this site, every example has a Console box under the result that shows what the code printed and any error with its line number. Errors are normal: read the message, find the line, fix it and run again. That loop is most of programming.
Console
- Console messages, errors, form data and clicked links appear here.
The console shows three lines. 2 + 3 adds numbers and gives 5, but "2" + "3" joins two pieces of text and gives 23. The quotes make all the difference.
Sign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 2 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
What is the difference between let and const in JavaScript?
Both create block-scoped variables. A const cannot be reassigned after it is created, while a let can. Use const by default and let for values that must change, such as a counter or a running total.
Should I still use var in JavaScript?
No, not in new code. var is function-scoped and hoisted, which causes confusing bugs. let and const fix that and are supported in every current browser. You only need to recognise var when reading older code.
Why does 0.1 + 0.2 not equal 0.3 in JavaScript?
Numbers are stored in binary floating point, as in most languages, and 0.1 and 0.2 have no exact binary form. The tiny error shows when you print the sum. For money, calculate with full precision and round once with toFixed(2) or Intl.NumberFormat when displaying.
Is JavaScript the same as Java?
No. They are different languages with different uses, and the similar name came from marketing in the 1990s. JavaScript runs in every browser and in Node.js; Java is mostly used for large back-end systems and Android apps.
Where do I see console.log output?
In the browser’s developer tools, in the Console tab: press F12, or Ctrl+Shift+I on Windows, or Cmd+Option+I on a Mac. In the lessons on this site, the Console box under each result shows the same output without opening anything.
Sources
Facts in this lesson were checked against these official pages on 5 November 2026.
- MDN: Storing the information you need (variables)
- MDN: Basic math in JavaScript (numbers and operators)
- MDN: Handling text (strings in JavaScript)
- MDN: const
- MDN: Template literals
- MDN: typeof
- MDN: Intl.NumberFormat
- Ecma International: ECMAScript language specification
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.