← Back to Scala Course | Chapter 2: Variables & Types | Lesson 3 of 8

Boolean

In this page:

  1. Boolean

Boolean

A Boolean holds either true or false and is the result of every comparison and logical expression. Booleans drive if statements and pattern match guards throughout Scala. Unlike some languages, Scala never implicitly converts other types to Boolean.

Note: Comparison operators like ==, >, and < always evaluate to a Boolean value.

Example: Boolean

markup
object Main extends App {
  val isActive: Boolean = true
  val isAdmin: Boolean = false
  val isAdult = 20 >= 18

  println(s"$isActive $isAdmin $isAdult")
}
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.