QuestenaPractice that shows what to review next
Topic lesson

Values and types: classify before you compare

About 6 min

Questions stay in the language in which they were published.

These questions ask you to classify values, read type checks, and predict comparisons or numeric operations. A reliable approach is to name the value category first, then apply the exact operation instead of relying on how the value looks.

Classify first, then apply the operation

Begin with the seven primitive families. Anything outside that list, including an array or callable function, belongs to the object side of the model. Then keep the value model separate from an operator label: typeof null produces the string object, while typeof Math.max produces function. NaN remains in the Number family even though its spelling may look like a separate category; do not invent a new primitive family from a value's spelling.

SignalDecision procedure and small example
A primitive is reassignedSeparate the binding from the value. After let word = "oak" and word = "elm", the binding points elsewhere; the earlier string was not altered.
Two objects are comparedAsk whether both expressions reach the same object. If a = [4] and b = [4], a === b is false; matching contents do not create shared identity.
Two symbols have matching descriptionsTreat each Symbol call as a fresh identity. The description is a label, not a link between the created values.
Number arithmetic uses decimal-looking fractionsRemember that Number uses binary floating-point. Some decimal fractions lack an exact binary representation, but that does not make every integer or every decimal calculation inaccurate.
A BigInt appearsAn integer literal such as 17n uses the n suffix and has no fractional part. Before arithmetic, make both operands BigInt or both Number; 17n + 1 mixes the families and throws a TypeError. Keep that arithmetic restriction separate from comparison: mixing the two numeric families does not make every comparison operator throw.
Object.is is usedUse its own special-case rules rather than borrowing ===. It treats NaN as the same as itself and distinguishes positive zero from negative zero.

The tempting wrong routes

Try it

Question 5

Spot the false statement about primitive value immutability.

  1. A string operation cannot alter the original string value
  2. A number value cannot be changed internally
  3. A variable can later hold a different primitive value
  4. Reassigning a variable mutates its old primitive value
Question 6

Why can the test 0.1 + 0.2 === 0.3 evaluate to false in JavaScript?

  1. Some decimal fractions are inexact in binary floating-point
  2. Strict equality rounds both sides to whole numbers
  3. Every JavaScript integer is stored approximately
  4. Addition always converts decimal numbers to strings
Question 7

Complete the code-reading result: typeof NaN evaluates to which string?

  1. NaN
  2. number
  3. undefined
  4. object
Start drillPractice this topic
Values and types: classify before you compare · Questena