...

/

Variables in Scala

Variables in Scala

In the following lesson, you will be introduced to variables and how they are declared in Scala.

Introduction

Imagine you have multiple boxes and in each box, you can store one item. Before you can store anything, you need to decide what type of item can be stored in each box. But now you have so many boxes, you don’t remember what is in each one. You decide to give each box a unique label. This will help you keep track of what each one contains. The labels act as identifiers, giving each box a unique identity.

In the same way, a variable is a small box used to store data. When we assign a value to a variable, we are basically putting something in a box. When you declare a variable, you give it a unique name or identifier, define the type of data it can store, and set its initial value. While most programming languages have a similar way of ...