Skip to content
UNWIND Code Lab Co-funded by the European Union
Values: Types, Operators and Math
Log In

Values: Types, Operators and Math

  • 5 min reading
  • 6 min activity
0 of 5 tasks doneup to 95 XP
  1. Quick recall10 XPOptional
  2. Which type?15 XPTo do
  3. Text plus number10 XPTo do
  4. Slide bug: the missing hypotenuse30 XPTo do
  5. Type detective30 XPTo do

Mission 4, step 3. Programs work with values: names, numbers, yes and no. Today you learn the kinds of values and how JavaScript calculates with them.

In this lesson
  • Create variables with let and const.
  • Tell the types of values apart and check them with typeof.
  • Calculate with operators, join text with + and use Math.
Remember

In lesson 4.2 you wrote const title = document.getElementById("title");. What did const do there?

Quick check

Quick recall

10 XP

Variables

A variable is a box with a name for a value. let makes a box whose value can change. const makes a box that keeps its value. Older code uses var; you do not need it.

let age = 25;         // can change: age = 26;
const name = "Ayla";  // stays "Ayla"

Types of values

The type is the kind of a value. The operator typeof tells you the type: typeof 5 gives "number".

TypeExamplesMeaning
string"Ayla", "0000 000"Text in quotes, also digits in quotes
number25, 3.14, -5A number without quotes
booleantrue, falseYes or no
undefinedlet box;No value yet
nulllet wallet = null;Empty on purpose
object{ name: "Ayla", age: 25 }Named values in one box; read one with person.name

Good to know: typeof null gives "object". It is an old mistake in JavaScript that was never changed.

Grouping

Which type?

Required 15 XP

Operators

  • + - * / work as in maths.
  • % gives the remainder: 10 % 3 is 1. An even number has remainder 0 when you divide it by 2.
  • ++ adds 1, -- takes 1 away.
  • score += 10 means score = score + 10; -= takes away.
let score = 0;   // create it first
score += 10;     // 10
score++;         // 11

The slide uses score += 10 without creating score, which stops with an error. With text, + joins:

console.log("Lena" + " " + "Weber");   // Lena Weber
console.log("5" + 5);                  // 55: one value is text
Quick check

Text plus number

Required 10 XP

Now be a type detective. This exercise counts for the Console Detective badge.

Practice

Type detective

Required 30 XP

Find out the type of four values with typeof. Then join the city and the number in one sentence.

The Math object

CodeResult
Math.round(4.6) (nearest whole number)5
Math.ceil(4.1) (always up) and Math.floor(4.9) (always down)5 and 4
Math.min(10, 5, 20, -3) and Math.max(10, 5, 20)-3 and 20
Math.abs(-50) (without the minus)50
Math.pow(2, 3) and Math.sqrt(16)8 and 4
Math.random()A number from 0 up to 1, never 1, for example 0.8234

Worked example: the hypotenuse

The slides use Pythagoras: in a triangle with a right angle, a² + b² = c². With a = 3 and b = 4, c is 5.

Worked example
  1. Store the sides

    let a = 3; and let b = 4;

  2. Calculate and store

    Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)). Put the result into a variable, or it is lost.

  3. Print

    console.log("Hypotenuse: " + c);

The slide's code misses one thing in step 2. Run it, read the message, fix it. This counts for the Bug Hunter badge.

Practice

Slide bug: the missing hypotenuse

Required 30 XP

This code comes from a course slide. It has a small bug. Find it and fix it.

Variable
A box with a name for a value.
Type
The kind of a value: string, number, boolean, undefined, null or object.
typeof
An operator that gives the type as text.
Operator
A sign that works with values, like +, % or +=.

In short

  • let for values that change, const for values that stay.
  • typeof names the type of a value.
  • % gives the remainder, += changes a value, + joins text.
  • Math rounds and calculates; Math.random() makes random numbers.
Next time

Text tools and arrays: many values in one list.

Sources

  1. MDN Web Docs (2026). Storing the information you need: Variables.
  2. MDN Web Docs (2026). JavaScript data types and data structures and typeof.
  3. MDN Web Docs (2026). Basic math in JavaScript: numbers and operators and Remainder (%).
  4. MDN Web Docs (2026). Math.

End of the lesson

This lesson: 0 of 105 XP

Code Cards in this lesson: 14

  • let
  • const
  • typeof
  • string
  • number
  • boolean
  • undefined
  • object
  • + - * /
  • ++
  • +=
  • "a" + "b"
  • Math.round()
  • Math.random()