Programming Basics: Your First Steps

Lesson 2 of 5

Data Types and Operators

Every value in JavaScript has a type, and the type determines what you can do with it.

JavaScript

Common types

TypeExample
number16, 19.99, -3
string"Space Quest"
booleantrue / false

Operators

  • Arithmetic: + - * / work on numbers as you'd expect. + on two strings joins them instead of adding.
  • Comparison: === checks if two values are equal (strictly, without converting types), !== checks if they're not equal, <, >, <=, >= compare numbers.
JavaScript

Why === and not ==

JavaScript also has ==, which converts types before comparing ("5" == 5 is true), that hidden conversion causes subtle bugs. Prefer ===/!==, which compare exactly what you wrote.

📝 Data Types & Operators Quiz

Passing score: 70%
  1. 1.What does === check, unlike ==?

  2. 2.5 === "5" evaluates to ____, since the two values have different types.

  3. 3.Using + on two strings joins (concatenates) them instead of adding.