Lesson 2 of 17
Variables
Variables in Kotlin
Kotlin has two kinds of variables:
val— immutable (read-only), likeconstin other languagesvar— mutable, can be reassigned
val name = "Alice" // cannot be changed
var score = 0 // can be changed
score = 100
Kotlin infers types automatically, so you rarely need to write them explicitly:
val age: Int = 25 // explicit type
val city = "Berlin" // inferred as String
Your Turn
Create a val named language with the value "Kotlin", then create a var named version starting at 1, reassign it to 2, and print both.
JS Transpiler loading...
Loading...
Click "Run" to execute your code.