Display JavaScript Output with console.log()
Quick answer
console.log() asks the host to display one or more values for inspection. It is useful while learning and debugging, but it does not return the displayed value as a calculation result.
How it works
In console.log(value), the parentheses contain the value to display. For now, use one value per call so the result is easy to predict. Separate calls in these synchronous examples happen in the written order. Console formatting of complex values can vary by host.
Expected console output (Node.js):
4 + 59The quoted expression is text; the unquoted addition is evaluated.
Expected console output (Node.js):
Start12DoneEach call produces a separate output in this Node.js example.
Common mistakes
Do not put quotation marks around a calculation if you want its numeric result. Do not confuse displaying a result with returning it from a function; returning is introduced later in this chapter.
Practice
Predict the output of two calls before running them: one containing a quoted calculation and one containing the actual calculation.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Display JavaScript Output with console.log() — Knowledge Check
Review the concept and apply it to a new example.
What does console.log("2 + 3") display?
What does console.log(2 + 3) display?
Two synchronous calls display "First" then "Second". Which call happens first?
What is the primary purpose of console.log()?
Two values look alike in a console. What can you conclude?