A+ A-

Javascript Code for browser alert box

The browser alert box:

While these are incredibly useful for debugging (and learning the language), they are a horrible way to communicate with the user. Alert boxes will stop your scripts from running until the user clicks the OK button, and it has all the charm and grace of all those pop-up windows everyone spent so many years trying to get rid of!


[code type="JavaScript"]<html>
<head>
</head>
<body>
<script type="text/javascript">
alert('Hello World!');
</script>
</body>
</html>[/code]

One of the most important things to do when learning a new language is to master basic input and output which is why hello world has become almost a cliché in programming textbooks. For Javascript you need three hello worlds because there are three ways to communicate with the user, each increasingly more useful than the last.