Variable Types
There are many types of variables, which we will progressively explore in upcoming articles. In this article, we will cover the 4 most basic ones:
- String
- Int
- Double
- Bool
String
String variables can only store text (words, phrases, etc.). And whenever we assign a value of this type, we must enclose it in quotation marks.
var myName: String = "Pablo"
Int
Int variables store integer numbers, which can be either negative or positive.
var myAge: Int = 4
Double
In this case, you can store not only integer numbers but also decimal numbers, both negative and positive.
var averageGrade: Double = 7.3
Bool
Bool variables are undoubtedly the most important. Their value
var userAuthorized: Bool = true
var userDeleted: Bool = false
Why do we need different types of variables?
In the following articles, you will learn how to work with variables, make operations with them, store them in a database, send them to a server, etc. For all of this, itβs important that the system knows what type each variable is. This will also help you when, for example, you accidentally try to to not allowed operations like add a name (String) to an age (Int). But don't worry, weβll cover that later.
Be the first to comment