Chapter 12: Adding Just Enough JavaScript

JavaScript is a Web programming language that you can use with HTML5. It can be used to access certain parts of your Web pages written in HTML5 and do other things that simply cannot be done without JavaScript. This chapter introduces some basic features that are going to be used specifically with HTML5 elements.

JavaScript is considered a scripting language because it’s interpreted by the browser at runtime (when you actually open a Web page) rather than compiled and stored on your computer as a binary file. Slightly different versions of JavaScript can creep in with different implementations of the

language on different browsers. Because JavaScript meets an ECMAScript standard (ECMA-262), these differences are slight, and what I’ll be discussing in this chapter are only those aspects of JavaScript that you can use with HTML5.

Finally, JavaScript and Java have nothing in common — JavaScript is not based on an interpreted version of Java. They could be named dogs and cats or apples and oranges for all they have in common. The name with java in it sounded better. So, if you want to look up something on the Web about JavaScript, you won’t be helped if you just look for Java.

Inserting JavaScript into HTML5 Pages

JavaScript programs are placed in the head of a Web page because that part of the Web page loads first, so it’s ready when the rest of the page loads. They act very much like CSS3 scripts, and like CSS3 scripts, they can be placed ...

Get Smashing Html5 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.