The if-else statement is used to execute different blocks of code based on a condition. JavaScript can be used to handle events such as mouse clicks, keyboard input, and form submissions.