Ch 2 · Your First JavaScript Program · JavaScript

Topic 2 of 13 in JavaScript — Complete Tutorial (Beginner) — 3 lessons.

Hello World!

Every programmer starts here. "Hello, World!" is a simple program that just shows text on screen — and it proves your setup is working.

Understanding console.log()

The console is like a private notepad for your program. Whatever you tell console.log() to display, it shows up there — numbers, text, results of calculations, anything. It is the most important tool you have for checking whether your code is doing what you expect.

New Lines, Quotes and Escape Characters

Sometimes the text you want to show contains characters that JavaScript would normally treat as code. A quote mark is the classic problem: in "She said "hi"" JavaScript thinks the text ends at the second quote mark, and the program fails with an error. There are two fixes. You can wrap the text in the other kind of quote, so single quotes on the outside can hold double quotes on the inside, and the other way round. Or you can put a backslash \ in front of the quote mark. The backslash is called an escape character: it tells JavaScript "treat the next character as ordinary text". The same idea gives you \n, which starts a new line, and \\, which prints a single backslash.

All topics in JavaScript Beginner

  1. Introduction to Programming & JavaScript
  2. Your First JavaScript Program
  3. Variables — Your Data Containers
  4. Data Types — Kinds of Values
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Arrays — Lists of Data
  10. Objects & Classes
  11. Strings — Working with Text
  12. Error Handling
  13. Mini-Projects & Practice