Prepare for the Blockchain Developer Certification. Master blockchain concepts with flashcards and multiple choice questions. Explanation-based learning for your success!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which keyword in Solidity declares an unchangeable value after its initial assignment?

  1. final

  2. immutable

  3. constant

  4. static

The correct answer is: immutable

The keyword that declares an unchangeable value after its initial assignment in Solidity is "immutable." When a variable is declared as immutable, it can be assigned a value only during its declaration or within the constructor of the contract. Once this value has been set, it cannot be modified later in the contract. This allows for the creation of values that are known at deployment time but can still be dynamic in a way that "constant" variables cannot. While constants must be assigned at compile time and remain fixed, immutable variables provide more flexibility because they can be set to a value that depends on the constructor parameters or other factors at the time the contract is deployed. In summary, the choice of using "immutable" allows developers to optimize gas usage and enforce a certain level of security by ensuring that the values cannot be altered after initialization, making it a preferred approach for certain implementations in smart contracts.