Boolean Values
Part of the Fundamentals section of Coddy's Solidity journey. Lesson 8 of 53.
A bool records one of two values: true or false. Use it to represent a condition such as whether a setting is enabled. These values are keywords without quotation marks. A boolean is not a number and does not become one automatically.
The statements in this excerpt run inside the provided main function.
bool enabled = false;
enabled = true;
console.log(enabled);The second assignment changes the setting. The console helper displays booleans as lowercase true or false. A string such as "true" is text, so it cannot replace the boolean keyword in a bool declaration.
A bool variable holds true or false, and assignment can replace either value.
Challenge
EasyCopy active into a local boolean isOpen, then print it.
The tests pass arguments to main in this order: bool active. Each test starts with fresh contract state.
Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.
Try it yourself
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
function main(bool active) external view {
// Write your solution here.
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2Variables and Types
Unsigned IntegersInputs and OutputSigned IntegersBoolean ValuesStrings in MemoryProfile CardPractice on your own: Solidity playground