Running code, values, and output

Objective

Distinguish a value, printed output, and a returned answer.

Learning objective

Distinguish a value, printed output, and a returned answer.

Explanation

JavaScript evaluates expressions to produce values. Numbers are written without quotes; text is enclosed in quotes. console.log displays a value for a person to inspect. The practice runner checks the value returned by your function, not the displayed text.

Start by predicting the example output, then run it. Early exercises supply a function wrapper: replace the expression after return without changing the surrounding structure. A comment beginning with // explains code without executing. You will learn to define your own functions later. console.assert is a supplied check: it reports a failure when its condition is false. Nothing in this course requires a browser document or network connection.

Worked example

console.log("Hello, learner!");
console.log(2 + 3);
console.assert(2 + 3 === 5);

Common mistakes

Quoting an arithmetic expression makes it text. console.log returns undefined, so it is not a substitute for returning the requested answer.

Guided practice

Change the greeting and predict 4 + 2 before running it. In the supplied practice wrapper, return the number 7.

Independent practice

Try the exercises linked below. Predict an answer before running code, and explain one boundary case in your own words.

Recap

Distinguish a value, printed output, and a returned answer. Compare the result with your prediction and use small examples to explain any difference.