A program 程序 is a list of instructions for the computer. In JavaScript, each instruction is a statement 语句, and the computer runs the statements from top to bottom.
console.log(...) prints a value in the console 控制台, the text area under the code:
console.log("Hello, world!");
console.log(7 * 6); // 42
- Text goes inside quotes:
"Hello"or'Hello'. Numbers do not. - End each statement with a semicolon
;. JavaScript can often guess where one is missing, but writing it is clearer. - JavaScript is case-sensitive 区分大小写:
console.logworks,Console.Logdoes not.
To put a quote mark inside text, use the other kind of quote around it. A backslash 反斜杠 starts a special character: \n starts a new line.
console.log('She said "hi"'); // She said "hi"
console.log("It's mine"); // It's mine
console.log("Line one\nLine two"); // two lines: Line one, then Line two
console.log can print several values at once. It puts one space between them:
console.log("Total:", 3 + 4); // Total: 7
console.log(1, 2, 3); // 1 2 3