Skip to main content

Types and Operators

beginner14 min readLesson 29 of 143

Six value types cover most beginner code β€” strings, numbers, booleans, null, undefined β€” plus the operators that combine them.

Every value in JavaScript has a type. Six cover most beginner code.

The primitives

const name = "Ada"; // string β€” text in quotes
const year = 2026; // number β€” integers and decimals alike
const pi = 3.14159; // also a number
const isLive = true; // boolean β€” true or false
let nothing = null; // null β€” deliberately "no value"
let notSet; // undefined β€” declared, never assigned

null and undefined both mean "nothing here" β€” the difference is who did it: null is a deliberate choice by the programmer; undefined means the value was never set.

Numbers and arithmetic

const price = 19.99;
const quantity = 3;

price * quantity; // 59.97  (multiplication)
10 + 3; // 13
10 / 4; // 2.5
10 % 3; // 1   remainder β€” "% is the remainder operator"

% (remainder) is surprisingly useful: n % 2 === 0 tests whether a number is even.

Strings: joining and building

const first = "Ada";
const last = "Lovelace";

first +
  " " +
  last // "Ada Lovelace" β€” + joins strings
  `Full name: ${first} ${last}`; // template literal (backticks)
first.length; // 3 β€” strings have properties too
name.toUpperCase(); // "ADA" β€” and methods

Comparisons β†’ booleans

const age = 20;

age >= 18; // true
age === 20; // true  β€” strict equality (three equals: always use this)
age !== 21; // true  β€” strict inequality

Always use === and !==. The loose versions (==) do surprising type conversions β€” a classic bug source you will simply never need.

Logic: &&, ||, !

const age = 20;
const hasTicket = true;

age >= 18 && hasTicket; // true β€” AND: both sides must be true
age < 12 || age > 65; // false β€” OR: at least one side true
!hasTicket; // false β€” NOT: flips the boolean

What you learned

  • Six primitives; null (deliberate) vs undefined (not yet set)
  • Arithmetic including the remainder %
  • Template literals build strings; ===/!== for comparisons
  • &&, ||, ! combine booleans

Next: programs that decide and repeat.

Now practice

Types and Operators β€” PracticeHands-on practice for β€œTypes and Operators”: apply what you just learned in js-types-and-operators.1 challenge Β· Β· ~10 min