Lesson 2 of 15

Values & Variables

Values and Variables

Scala distinguishes between immutable values (val) and mutable variables (var):

val pi = 3.14159    // immutable — cannot be reassigned
var count = 0       // mutable — can be reassigned
count = 10

Scala infers types automatically. You can also annotate them explicitly:

val name: String = "Alice"
var age: Int = 30

Basic Types

TypeExample
Int42
Double3.14
String"hello"
Booleantrue, false

Your Task

Create a val x = 10, a var y = 5, then reassign y to y + x, and print y.

JS Transpiler loading...
Loading...
Click "Run" to execute your code.