KodingKaro
JavaScript · Beginner · Data Types

Objects, arrays, and references

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 order = { items: ['tea', 'bread'] };
const sameOrder = order;
sameOrder.items.push('fruit');
console.log(order.items.length);

Expected output: 3

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 name = 'Mira';
console.log(typeof name);

Expected output: string

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 practice best avoids the common mistake in Data Types?

Show explanation

Use strict equality, explicit conversions, and clear data shapes. Avoid relying on implicit coercion.

Practical example

javascript
const name = 'Mira';
console.log(typeof name);

Expected result:

string

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