Quiz Entry - updated: 2026.07.30
What is a mapping, and what value does an unset key return?
A mapping is a key-to-value store — like a hash table or dictionary — declared mapping(KeyType => ValueType). Every possible key already "exists" holding the value type's zero value.
mapping(string => uint256) public nameToFavoriteNumber;
nameToFavoriteNumber["Patrick"] = 7; // set
// nameToFavoriteNumber["Alice"] is 0 (never set -> zero value)
A mapping lets you jump straight to a value by its key instead of scanning a list — looking up a name in an array of hundreds means iterating; a mapping returns the answer directly. The catch is there is no "not found": because Solidity has no null, every conceivable key is pre-initialised to the value type's default. So a lookup on a key you never wrote returns 0 (for a uint256 value), not an error. Mappings also can't be iterated and don't track their own length.
Go deeper:
Solidity docs: mapping types — key/value semantics and why keys aren't enumerable.