console.log
Printing output.
Console dot log is how a program talks to you. You'll use it constantly, to see results, and to find bugs. It can print text, numbers, and several things at once.

- How a program talks to you
- See results, find bugs
- Text, numbers, many things
Printing different things
Text goes in quotes. Numbers don't need quotes, and JavaScript can do maths right inside the brackets. Separate several values with commas, and they're printed with spaces between them. Run it.
console.log("I am learning JavaScript");
console.log(42);
console.log(10 + 5);
console.log("Score:", 90, "points");I am learning JavaScript 42 15 Score: 90 points
Quotes matter
Anything in quotes is text, exactly as written. So console dot log of ten plus five, in quotes, prints the characters ten plus five. Without quotes, it prints fifteen. Double quotes and single quotes both work. Just start and end with the same kind.
| key | value |
|---|---|
| "10 + 5" | prints 10 + 5 |
| 10 + 5 | prints 15 |
| 'single' | also works |
| Match | start and end the same |
Printing several values
Console dot log can print many values at once, separated by commas, and it puts a space between them. It can print the result of a calculation, and even a list of values in square brackets. Console dot log with nothing inside prints an empty line, which is handy for spacing out your output. Run it.
console.log("Apples:", 3, "Pears:", 5);
console.log("Total fruit:", 3 + 5);
console.log();
console.log(["red", "green", "blue"]);
console.log("Done!");Apples: 3 Pears: 5 Total fruit: 8 [ 'red', 'green', 'blue' ] Done!
Summary
Console dot log prints text, numbers, and calculations. Commas separate several values. Next, comments and statements.
Key takeaways- console.log(...)
- Quotes for text
- Commas for several