Primitive values and types
This lesson applies Data Types concepts to code you can run and adapt.
✓ What you will learn in this topic
- Explain key Data Types concepts.
- Read and adapt the examples.
- Apply the idea to a small real interface or data task.
Concept explanation
Strings, numbers, booleans, undefined, null, BigInt, symbols, arrays, objects, typeof, and primitive/reference behavior.
These concepts appear in everyday interfaces and data transformations; understanding the trade-offs helps you choose a reliable implementation.
Syntax
The examples use standard ECMAScript syntax. Run console examples in a browser console or Node.js; DOM examples require a browser page containing the referenced elements.
Example 1: a small experiment
Run this compact example to observe the core rule before applying it to a larger feature.
const name = 'Mira';
console.log(typeof name);Expected output: string
Why it is useful: A small experiment makes the value or behavior easy to inspect.
Example 2: a practical feature
This example models a small piece of application behavior. Adapt its values and inspect what changes.
const order = { items: ['tea', 'bread'] };
const sameOrder = order;
sameOrder.items.push('fruit');
console.log(order.items.length);Expected output: 3
Why it is useful: The same pattern can be extended into a real feature without tying the entire application to one large block of code.
Common mistakes
Treat typeof null as a historical quirk: it returns "object". Use Array.isArray() when distinguishing arrays.
Best practices
Use strict equality, explicit conversions, and clear data shapes. Avoid relying on implicit coercion.
Practice exercise
Explain why changing sameOrder.items also changes what is observed through order.
Lesson summary
Strings, numbers, booleans, undefined, null, BigInt, symbols, arrays, objects, typeof, and primitive/reference behavior.
Knowledge check
Which statement best describes an important idea in Data Types?
Show explanation
Strings, numbers, booleans, undefined, null, BigInt, symbols, arrays, objects, typeof, and primitive/reference behavior.
Practical example
javascriptconst order = { items: ['tea', 'bread'] };
const sameOrder = order;
sameOrder.items.push('fruit');
console.log(order.items.length);
Expected result:
3
Hands-on practice task
Explain why changing sameOrder.items also changes what is observed through order.
In this section
Other lessons in Data Types
Broaden your knowledge
Related learning topics
CSS
Learn to style, lay out, and adapt interfaces with a complete course from CSS foundations through advanced responsive architecture.
HTML
Learn to structure accessible, meaningful web pages with a complete HTML course from first document to professional application patterns.