Booleans
Explore how Dart's bool data type represents true and false values, including naming conventions, type inference, and nullable booleans. Understand the role of booleans in conditional logic to build clear and maintainable Dart applications.
We'll cover the following...
Dart uses the bool data type to represent boolean values. A boolean has only two possible values: true and false.
We can think of a boolean like a basic light switch. The switch is either completely ON (true) or completely OFF (false). There is no in-between state.
To create a boolean variable, we use the bool keyword and assign it one of these two literal values.
Lines 1–4: We define our
mainfunction as the entry point for the code.Line 2: We declare a variable named
isRunningof typebooland assign it an initial value oftrue.Line 3: We print the value of
isRunningto the console. The program outputs the wordtrue.
It is helpful to note that while the ...