Variables & Data Types
EasyIn plain terms
Variables are named containers for data. Instead of repeating a value everywhere, you store it once and use the name. For example, userName = "Alice" lets you refer to userName later.
Data types describe the kind of value: numbers for math, strings for text, booleans for true/false. Some languages require you to declare the type; others infer it. Understanding types helps you avoid bugs (e.g. adding a number to a string by mistake) and choose the right operations.
What you need to know
- •Variable: named storage for a value
- •Common types: number, string, boolean
- •Declaration and assignment
Example
Code is language-agnostic in spirit; adapt the idea to your language:
// Variables hold data
let count = 0;
const name = "Student";
let isActive = true;
// Types matter
let a = 5;
let b = "5";
// a + b might be "55" (string) or 10 (number) depending on languageWhy this matters
Interviewers may ask about type systems (static vs dynamic), mutability, and how you choose names. Strong typing and clear naming reduce bugs in production.
How it connects
Variables hold the data that functions and objects work on. In OOP, object properties are variables; in SOLID, you often depend on abstractions (interfaces) rather than concrete types—so understanding types matters for design.
Interview focus
Be ready to explain these; they come up often.
- ▸Explain the difference between declaration and assignment.
- ▸Static vs dynamic typing: pros and cons (safety vs flexibility).
- ▸Why naming matters: "code is read more than it is written."
Learn more
Dive deeper with these resources: