Complete Kotlin Tutorial: Part 3 (The Variables)

Ajit Kumar Sahoo
5 min readMay 20, 2022

If you are new to this series, start from here

The previous post, Part 2 is here

Now, let’s continue with our journey by understanding the proper use of variables in Kotlin.

Understanding Variables and Keywords

Before going any further let me tell you what are variables and keywords in any programming language.

Variables are simply placeholders in which we store a specific type of data. Depending on the type of data it holds, it occupies a certain space/memory in the system.

Keywords are predefined and special reserved words meant for a specific purpose and we cannot have variables having the same name as the keywords.

I hope that you got a general idea about variables and keywords. If you didn’t, then please ask your query in the comments.

Okay, now getting back to understanding var and val keywords. As I have already said in my earlier posts that, Kotlin is a statically typed programming language. So, we need to declare variables before using them.

Variables in Kotlin can be declared in two specific ways:-

  • Using the var keyword
  • Using the val keyword

--

--