Previous Page
Next Page

What JavaScript Is

JavaScript is a programming language that you can use to add interactivity to your Web pages. But if you're not a programmer, don't panic; there are lots of JavaScripts available on the Web that you can copy and modify for your own use with a minimum of effort. In fact, standing on the shoulders of other programmers in this way is a great technique for getting comfortable with JavaScript.

To make it easier for you to get up and running with JavaScript, we have set up a Web site that supplements this book. We've included all the scripts in the book (so you don't have to type them in yourself!), as well as additional notes, addenda, and updates. You can find our site at http://www.javascriptworld.com.

You'll often see JavaScript referred to as a "scripting language," with the implication that it is somehow easier to script than to program. It's a distinction without a difference, in this case. A JavaScript script is a program that either is contained internally in an HTML page (the original method of scripting) or resides in an external file (the now-preferred method). On HTML pages, because it is enclosed in the <script> tag, the text of the script doesn't appear on the user's screen, and the Web browser knows to run the JavaScript program. The <script> tag is most often found within the <head> section of the HTML page, though you can, if you wish, have scripts in the <body> section. Internal scripts that write text to the screen or that write HTML are best put in the <body> section, as in Script 1.1. If you're unfamiliar with these HTML concepts and you need more information about HTML, we suggest that you check out Elizabeth Castro's HTML, XHTML, and CSS, Sixth Edition: Visual QuickStart Guide, also available from Peachpit Press.

Script 1.1. This very simple script types "Hello, Cleveland!" into the browser window.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <title>Barely a script at all</title>
</head>
<body bgcolor="#FFFFFF">
<h1>
     <script language="Javascript" type="text/javascript">
       document.write("Hello, Cleveland!")
     </script>
</h1>
</body>
</html>


Previous Page
Next Page