Welcome back! In our journey to unlock the logic of computer algorithms, we've established that algorithms are sets of instructions. But what kind of information do these instructions actually operate on? This is where data types come in. Think of data types as the fundamental categories of information a computer can understand and manipulate. Just like you wouldn't try to pour water into a sieve or toast a frozen loaf of bread without preparation, computers need to know the nature of the data they're dealing with to process it correctly.
At the most basic level, we can broadly categorize data into a few key types. Understanding these will be crucial as we build more complex algorithms. Let's explore some of the most common ones.
This is perhaps the most intuitive data type. Computers are excellent at performing mathematical operations, and numbers are the foundation for this. We often see two main sub-types of numbers:
- Integers: These are whole numbers, both positive and negative, without any decimal point. Examples include
10,-5,0,1000.
- Floating-Point Numbers (or Floats): These are numbers that have a decimal point, allowing for fractional values. Examples include
3.14,-2.5,0.001,99.99.
let age = 30; // Integer
let price = 19.99; // Floating-point numberComputers also deal with text, which we call 'strings'. A string is a sequence of characters, which can include letters, numbers, symbols, and spaces. Strings are typically enclosed in quotation marks to distinguish them from commands or variable names. Examples include 'Hello, world!', 'Algorithm', 'User123', '#$%&'.