Aral Code

Variables & Data Lesson 6 of 30

JavaScript Data Types — Strings, Numbers, Booleans and More

The kinds of values JavaScript works with — string, number, boolean, undefined, null, plus arrays and objects — and how to check a type with typeof.

Not all values are the same kind. A name is text, an age is a number, and "is the student present?" is a yes-or-no answer. These kinds are called data types, and JavaScript treats each one differently.

The main data types

TypeExampleUsed for
String"Maria", 'Grade 10'Text
Number16, 89.5, -3Whole numbers and decimals
Booleantrue, falseYes/no, on/off
UndefinedundefinedNo value assigned yet
NullnullIntentionally empty
Array["Math", "Science"]A list of values
Object{ name: "Ana", age: 15 }A record with named parts

Strings

A string is text inside quotes. You can use double quotes "..." or single quotes '...'. Pick one style and stick to it.

let school = "Mabini High School";
let motto = 'Galing at Malasakit';
let quote = "Sabi ni Rizal: 'Ang hindi lumingon sa pinanggalingan...'";

To put a quote inside a string, use the other kind of quote around it, as in the last line.

Numbers

JavaScript has one number type for both whole numbers and decimals. Numbers are written without quotes:

let age = 15;
let average = 89.75;
let temperature = -2;
Example Number vs. string
<pre id="out"></pre>
<script>
  const a = 15 + 1;
  const b = "15" + 1;
  const c = Number("15") + 1;
  document.getElementById("out").textContent =
    "15 + 1 = " + a + "\n" +
    '"15" + 1 = ' + b + "\n" +
    'Number("15") + 1 = ' + c;
</script>

Booleans

A boolean has only two possible values: true or false. They answer yes/no questions and are the heart of decision-making:

let isPresent = true;
let hasPaid = false;
let passed = 82 >= 75;   // true

undefined and null

Both mean "no value", with a small difference:

  • undefined: the variable exists but nothing was ever put inside. JavaScript sets this automatically.
  • null: you, the programmer, deliberately set it to "empty". For example, let selectedSeat = null; before a seat is chosen.

Arrays and objects (preview)

These hold many values at once. They get full lessons later, but here's a peek:

const subjects = ["Math", "Science", "English"];         // array (list)
const student = { name: "Ana", grade: 9, present: true }; // object (record)

Checking a type with typeof

Example typeof tells you the type
<pre id="out"></pre>
<script>
  const values = ["Juan", 42, 3.5, true, undefined];
  let text = "";
  for (const v of values) {
    text += String(v) + " → " + typeof v + "\n";
  }
  text += "null → " + typeof null + "  (a famous old bug!)\n";
  text += "[1, 2] → " + typeof [1, 2];
  document.getElementById("out").textContent = text;
</script>

Notice two oddities: typeof null says "object" (a mistake from 1995 that can't be fixed now without breaking old websites), and arrays also say "object". To check for an array, use Array.isArray(value).

Dynamic types

A JavaScript variable can hold any type, and can even change type later. That's flexible, but it's also why bugs like "15" + 1 happen. Some languages, like Java and C#, don't allow this. You'll see the difference if you take those courses.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. What is the type of "89"?
2. What does "5" + 5 give?
3. Which value is a boolean?
4. What does typeof 3.14 return?

By Sir Reyel · Last updated 2026-12-04