Values, Types, and Expressions
Primitive Types
Work with numbers and booleans, and read a value's type.
Primitive Types
primitive_types.js
const n = 42;
const big = n > 10;
const kind = typeof n;
console.log("n=" + n);
console.log("big=" + big);
console.log("kind=" + kind);
Follow the Primitives
nstarts at42.big = n > 10becomestrue.kind = typeof nbecomesnumber.- The program prints
n=42,big=true, andkind=number. | n | big | kind | | --- | --- | --- | | 7 | false | number | | 42 | true | number | | 100 | true | number |
primitive-types
Numbers and booleans are primitive values. A comparison yields a boolean, and `typeof` reports the type name as a string.
Exercise: primitive_types.js
Reproduce big=true and kind=number for n=42, then use the pinned n values 7 and 100 to predict big.