Variables II
Most common types of variables.
Variables II
Most common types of variables.
0
0
Checkbox to mark video as read
Mark as read

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 only stores the states "True" or "False". While this might not make much sense right now, any code needs to make condition checks to, for example, display different information on the screen.

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.

course

Quiz Time!

0 Comments

Join the community to comment
Sign Up
I have an account
Be the first to comment

Accept Cookies

We use cookies to collect and analyze information on site performance and usage, in order to provide you with better service.

Check our Privacy Policy