Skip to content

Chapter 3 of 33

Variables and Data Types

Use var, let, const, primitives, objects, coercion, and runtime type inspection.

34 minutes 10 quick checksBy Subha Prasad
Lesson 3 of 33Course navigation

Lesson content

Read, practise, then check your understanding

JavaScript primitives are string, number, bigint, boolean, symbol, undefined, and null. Everything else is an object. Variables hold values without a fixed declared type.

Bindings

const course = "JavaScript";
let completed = 0;
completed += 1;

const settings = { theme: "dark" };
settings.theme = "light"; // object mutates; binding does not

Prefer const, then let when reassignment is required. var is function-scoped, hoisted, and redeclarable, so it is mostly legacy. typeof null is historically "object"; use value === null. Number.isNaN checks NaN without coercion. Learn truthiness but do not let implicit conversion obscure contracts. Objects compare by identity, while primitives compare by value.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes var?
Which JavaScript term matches this description: A function-scoped declaration with hoisting and redeclaration behavior.
Which statement best describes let?
Which JavaScript term matches this description: A block-scoped reassignable lexical binding.
Which statement best describes const?
Which JavaScript term matches this description: A block-scoped binding that cannot be reassigned.
Which statement best describes primitive?
Which JavaScript term matches this description: An immutable non-object value such as string, number, bigint, boolean, symbol, null, or undefined.
Which statement best describes typeof?
Which JavaScript term matches this description: An operator returning a string describing a value's broad runtime category.

0 of 10 checks passed

Your progress is saved on this device.