Quiz Entry - updated: 2026.07.30
What is a function modifier, and how does the _; placeholder work?
A modifier is a reusable snippet of pre/post-check code you attach to a function's declaration; the _; marks where the function's own body executes.
modifier onlyOwner() {
require(msg.sender == owner, "sender is not owner");
_; // <- the decorated function's body runs here
}
function withdraw() public onlyOwner { // check runs first, then the body
// ... withdrawal logic
}
Modifiers let you avoid copy-pasting the same check into many functions. When withdraw is called, Solidity runs the onlyOwner body first; the _; is a placeholder meaning "now run the actual function code." So the require executes before withdrawal. Put the _; before the check and the order flips (body first, then check). Attaching onlyOwner to any function instantly gives it the same guard, keeping the code DRY.
Go deeper:
Solidity docs: function modifiers — the
_;placeholder and how modifiers compose.