Chapter 2

Placing JavaScript in an HTML File

Key Skills & Concepts

   Using the HTML Script Tags

   Creating Your First Script

   Using External JavaScript Files

   Using JavaScript Comments

Now that you have been introduced to JavaScript, you’re ready to start coding. This chapter introduces front-end (browser-based) JavaScript, while Chapter 3 will introduce how JavaScript can be used with Node.js.

Since front-end JavaScript code is included in HTML documents, you need to know how to tell Web browsers to run your scripts. The most common way to set off a script is to use the HTML <script> and </script> tags in your document. You can place your script tags in either the head or the body section of an HTML document.

This chapter first shows ...

Get JavaScript: A Beginner's Guide, Fifth Edition, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.