Alerts are useful for giving direct and immediate feedback that is difficult to ignore. In fact it’s almost impossible to ignore as the user must click OK before it goes away and they are allowed to access the page again.
However, on a note about design, alerts are not very user-friendly, precisely for the reason above. I recommend them primarily as programming tools for simple debugging and not something to make heavy use of where end users will be have to deal with them.
In this next example an alert displays the answer to a simple math problem:
Notice this time the code does not use single quotes around the numbers. If you change the code and add single quotes then it gets treated as straight text and not a math operation. Go ahead, try changing the line to look like this:
alert('2 + 3');
The resulting alert message should display 2 + 3, instead of what happened without the quotes when the numbers were added together and displayed as 5.