CH8-Default Value

The delete operator can reset the value of the variable to their default value.

CH-9 Constant and Immutable

What is the difference between the constant and immutable keywords in Solidity and how do I use them?

Feature constant immutable
Assignment Time Compile-Time At Declaration(Compile-Time) or Constructor(Deployment-Time)
Flexibility Less flexible; values must be known upfront More flexible; values can be set during deployment
Use Cases Fixed values like mathematical constants, fixed addresses Dynamic values like deployer address, configuration parameters
Gas Efficiency Slightly more efficient due to compile-time embedding Efficient; stored in bytecode after deployment
Reassignment Not allowed after initial assignment Not allowed after initial assignment

<aside> 💡

immutable Variables:

Assignment in Constructor:

Key Differences Between Compile Time and Deploy Time

Aspect Compile Time Deploy Time
When It Occurs Before deploying the contract During the actual deployment to the blockchain
What’s Set Values known beforehand (constants) Values determined at deployment (immutable variables)
Examples constant variables like MAX_SUPPLY immutable variables like owner set in the constructor
Analogy Writing and baking the recipe Opening the bakery to the public