Every Value Has a Type

Every value in a program belongs to a type, and the type determines what operations make sense. You can multiply numbers; you can uppercase text; you can't uppercase the number 42.

The core types you'll meet everywhere:

String: text in quotes: "Harriet", "42"

Number: 42, 3.14, -7 (Python splits these into int and float)

Boolean: True/False (Python), true/false (JavaScript)

Nothing: None (Python), null and undefined (JavaScript), Module 7's whole story

Asking a value its type

PYTHON

print(type(42))
print(type("42"))

JAVASCRIPT

console.log(typeof 42);
console.log(typeof "42"); 
Compare → Both languages can tell you a value's type at runtime. Notice: 42 and "42" report different types. Quotes change everything.
EXAMPLE
loading editor…
YOUR TURN
Your turn → Add a line that asks for the type of your own name in quotes, and another for the type of your birth year with no quotes.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: 42 versus "42" →
← Back