Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

65


Chapter 3 Getting started with JavaScript


CHAPTER 3 Getting started with JavaScript


W


hen you create HTML documents, you’ll almost always add behavior to make the
document more interactive. You might have animations or buttons that perform
various actions. Maybe you need to retrieve data from the server as a user is typing in a text
box. You can use JavaScript to accomplish these tasks because JavaScript is the program-
ming language of the web.
This chapter starts by introducing you to JavaScript and then examines the JavaScript
testing environment and test-driven development (TDD). As soon as you understand what
JavaScript is, you’ll want to start writing some code to see whether it runs the way you think
it should run. You’ll want to test your knowledge. You’ll want to write code for HTML docu-
ments with which you’re working.
By setting up a testing environment, you can write code and test it without requiring the
production HTML document. You want to have as much separation as possible between
your JavaScript code and your HTML document so you can write the JavaScript code inde-
pendently from the HTML document. The sooner you have a testing environment set up,
the sooner you’ll be able to start writing JavaScript code.

Lessons in this chapter:
■■Lesson 1: Introducing JavaScript 66
■■Lesson 2: Writing, testing, and debugging JavaScript 89
■■Lesson 3: Working with objects 108

Before you begin


To complete this book, you must have some understanding of web development. This
chapter requires the hardware and software listed in the “System requirements” section in
the book’s Introduction.
Free download pdf