Reading — step 1 of 5
Learn
Hello, World
Every language course starts with this program, and not just out of tradition. Before variables, loops, and functions can mean anything, you need the core feedback loop working: write code, run it, see what it printed. That loop is how you will learn everything else here — every exercise in this course is one round trip through it.
JavaScript is unusual in that it lives in two different worlds:
- The browser. Every browser ships a JavaScript engine; JS is the language of interactive web pages.
- The server, via Node.js. The same language running outside the browser — reading input, writing files, powering back ends.
This course uses the second one. When you press Run, your code is executed by Node.js in a sandbox, and everything it wrote to standard output (stdout) comes back to you. The grader then compares that output to the expected answer — character by character. Keep that in mind: in this course, printing exactly the right thing is how you pass.
console.log — how you print
console.log takes any value, writes it to stdout, and ends the line. The newline is automatic — you never need to add one yourself:
Two details worth noticing:
- Text needs quotes.
"Hello, World!"is a string — a piece of text data. Without quotes, JavaScript assumes you are naming a variable:
- Multiple arguments are printed joined by single spaces:
That second form becomes handy later for mixing labels and values on one line — remember it.
The semicolon at the end of each statement is technically optional in JavaScript, but virtually all production code uses semicolons, and this course will too.
Comments
Lines starting with // are ignored entirely when the program runs — they are notes for humans:
The exercise starters in this course use comments to tell you where to write your code.
The trap: almost-right output
The classic beginner failure in exact-output exercises is not a syntax error. The program runs fine and still fails, because it printed almost the right text:
Computers do not grade on intent. When an exercise shows expected output, copy its punctuation, capitalization, and spacing exactly.
Your exercise
Write one line of code that prints exactly:
Hello, JavaScript!
One console.log with the string in quotes is all it takes. The grader will catch: a capital H and a capital J, the comma directly after Hello, exactly one space before JavaScript, and the ! at the end. Two extra warnings: do not print Hello, World! — the lesson title is not the expected output — and do not add \n yourself, because console.log already ends the line.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…