root@coding-prodigies:~# โ–Š
// lesson 2 of 11 ยท 14 min

Syntax and types

โš‘ Report an issue with this lesson
val name = "Ada"          // immutable
var age = 28                 // mutable
val price: Double = 29.99

println("$name is $age years old")

val for values that never change, var for ones that do -- Kotlin nudges you toward val by making it the shorter, more natural default in most style guides.

Try it yourself

Exercise: Declare a val name and var age, then print them with a string template.
Expected output: open-ended โ€” there's no single correct output here, just get your code running without errors.
kotlin
Output

      
    

Run your code and get it working before marking this lesson complete.

// free preview

8 more lessons โ€” including Capstone project: a course catalog app โ€” plus a certificate are waiting.

Unlock the full course โ€” $149.99