Skip to content
val and var
step 1/5

Reading — step 1 of 5

Learn

~1 min readGetting Started

Kotlin has two variable keywords:

  • val — read-only (Kotlin's preferred default; like final in Java)
  • var — mutable
val name = "Alice"      // can't reassign
var count = 0            // can reassign
count = count + 1        // ok
// name = "Bob"          // compile error

val age: Int = 30         // explicit type (rarely needed — usually inferred)

Default to val. Reach for var only when you genuinely need to reassign — same advice as JavaScript's const/let.

Basic types: Int, Long, Double, Float, Boolean, Char, String. There's no separate int vs Integer — Kotlin types are objects with primitive optimization under the hood.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…