Programación Para Tontos

Fundamentos

Variables and data types explained with analogies

Understand variables and data types using labeled boxes instead of abstract theory.

A variable is like a labeled box where you store something to use later. The label is the variable's name, and what's inside is its value.

let age = 25;
let name = 'Sofia';
let isStudent = true;

Common data types

  • Number (25): for counting or calculating.
  • Text/string ('Sofia'): for words and phrases, always in quotes.
  • Boolean (true/false): for yes/no answers.
  • List/array ([1, 2, 3]): a box holding several things in order.
  • Object ({ name: 'Sofia', age: 25 }): a box with several inner labels.

Why does the type matter?

If you treat a number like text, weird things can happen:

console.log('5' + 1); // '51' (text gets glued together)
console.log(5 + 1);   // 6   (numbers get added)

Knowing what type of data is in each "box" avoids many common beginner mistakes.

Try it yourself

Try declaring three variables about yourself: your name, your age, and whether you like coding (true or false). That small exercise is already programming.