← Trail· Lesson 2 of 10
See this lesson in TypeScript →
Variables and types
Store values with let and const; recognize numbers, strings and booleans.

A variable gives a value a meaningful name, like a label. idade means age in the examples.
let or const?
- Use
constif you will not reassign the value. - Use
letif the value needs to change. - Update an existing variable with
idade = 20, without anotherlet.
= assigns a value; it does not compare values. Reassigning a const causes an error. Try it, then click Resetar (Reset).
| Type | Example | Meaning |
|---|---|---|
number |
20, 7.5 |
A number, possibly with a decimal part |
string |
'Ana', '20' |
Text in quotes |
boolean |
true, false |
True or false, without quotes |
20 and '20' are different. typeof 20 gives the string 'number'.
Try it
Change the values and compare the two console lines. Use a dot for decimal numbers.
Execute o código para ver a saída aqui.Exercise: discover the type
tipoDoValor(valor) means type of a value. It currently always returns 'number'. Replace the fixed value assigned to tipo with typeof valor.
Keep the function name and return tipo. Do not put quotes around typeof valor: you want the operator, not literal text. Click Verificar to check numbers, text and both boolean values. Feedback is in Portuguese.
Execute o código para ver a saída aqui.Edite o JavaScript e clique em Verificar.
Check your understanding
Predict the types of false, 'false' and 0 before running the code. Other types exist; we will cover them later.