BeginnerLesson 1 of 16
Hello World & console.log – JavaScript
Your first program, comments and output.
A JavaScript program is a text file (or a <script> block). With console.log() you write values to the console – the most important tool for experimenting and debugging.
console.log("Hello World!");
console.log("I am learning", "JavaScript");
console.log("Number:", 42, "True?", true);Multiple arguments are printed separated by a space. Comments start with // (single line) or sit between /* ... */ (multi-line):
// Single-line comment
/* Multi-line
comment */
console.log("a", "b", "c");
console.warn("This is a warning");
console.error("This is an error (only visually, the program keeps running)");
console.log({ name: "Ada", alter: 36 }); // objects are printed in a readable wayStatements usually end with a semicolon ;. JavaScript inserts missing semicolons automatically (ASI) – this mostly works, but in rare cases it leads to surprises. Stick to one style and let a tool like Prettier do the formatting.
WarningLines that start with
(, [ or a backtick can get "glued" to the previous line when a semicolon is missing. If you write without semicolons, you need to know this.TipClick "Run" to try the code right in your browser.
alert(), prompt() and document exist only in the browser – not in Node.js.