Why do we set the element's .onclick property equal to a function?

Question

Why do we set the element’s .onclick property equal to a function?

Answer

We usually want an event, like a mouse click, to trigger something to occur on our page, that something is defined by the function we assign to the DOM element’s .onclick property - every time the element is clicked it will call and execute the function, including any code inside the function body.