Val vs Var

Last updated

What is Val vs Var?

In Kotlin, both val and var are used to declare variables, but they differ in mutability. A val variable is immutable, meaning its value cannot be changed after it's initially assigned. Conversely, a var variable is mutable, allowing its value to be reassigned multiple times throughout the program's execution. Choosing between val and var depends on whether the variable's value needs to be modified after its initial assignment.

Free resources to learn Val vs Var

More in stage 4: Variables

Val vs Var: common questions

Can I learn Val vs Var in Hindi?

This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Val vs Var in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.

Is this Val vs Var tutorial for beginners?

It is lesson 9 of 153 in the free Kotlin roadmap, in stage 4, Variables. If you are new to Kotlin, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.

Still confused? Ask me