Skip to content
Aabha AI Academy
Skip to reading

JavaScript · Module 2

Answers and explanations · Represent information with values

Compare these references after your own attempt. You can read them at any time; they do not record a live model or vendor run.

A: interested starts as 6, then becomes 7. remaining is calculated once as 18 - 7, giving 11. Another assignment to interested does not rerun the earlier calculation.

B:

const incoming = "4";
const total = Number(incoming) + 2;
console.log(typeof incoming, typeof total, total);

The output is string, number, 6. Converting after addition would be too late: Number("42") is 42.

C:

const raw = " 5 ";
const trimmed = raw.trim();
const number = Number(trimmed);
console.log(trimmed === "", number, Number.isFinite(number));

For the three trials: trimmed 5 gives false, 5, true; many gives false, NaN, false; empty gives true, 0, true. The finite check alone cannot distinguish an omitted field from a deliberate zero. In a later branch, reject the blank case first.

Return to the exercise

Return to this module