A callback function is only run when a button is pressed. In your first example, the
console.log
is evaluated before any button is pressed, and is therefore printing undefined.