In the example on W3 School the, the alert is triggered when clicking a button. Notice the string passed into the function call is the one displayed.
Alert works for simply displaying a message to the user, but what if you need the user to confirm an action they made on your site? Let’s say, for example, that you want the user to confirm whether or not they want to delete an item after clicking the delete icon? This is a good habit because we don’t want the user to accidentally click delete and never be able to undo that mistake.
There’s one more piece that we need to understand though. In the above example, we have no idea to know which option the user chose. To do so, we can check the return value of the confirm() function. As you might expect, the method returns true if the user chooses “ok” and returns false if the user chooses “cancel”. Based on that return value, you can proceed to deleting the item or not. In the example below, I pop up an alert displaying the users choice.
In general, I would say that these built in pop ups aren’t used too often in modern web applications created by experienced developers. They aren’t exactly styled beautifully and may not provide the necessary functionality depending on what you’re looking for. There are more customizable options in JQuery for example that might be of interest, so if you need more, have a look around. However, for beginner web developers and for prototypes these functions become fairly useful.