2. Generating output
2.2. Output in the Alert Dialog Boxes
You can display your output into an alert box. In order to do it, you need to use the alert() method.
Sample Code:
The code above will result in an alert dialog box that will appear twice. The first alert box will display the text “Hello World!” while the second one will display “30”.
Some developers might write the keyword window.alert() in implementing this output statement. However, specifying the window keyword is optional. In JavaScript, the window object is a global scope object. With this, variables, properties, and methods are part of the window object by default.
Take note that when you want to display line breaks in a popup box or alert dialog box, use a backslash followed by the character n (\n).