O'Reilly logo

DOM Scripting: Web Design with JavaScript and the Document Object Model, Second Edition by Jeffrey Sambells, Jeremy Keith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. JavaScript Syntax

What this chapter covers:

  • Statements

  • Variables and arrays

  • Operators

  • Conditional statements and looping statements

  • Functions and objects

This chapter is a brief refresher in JavaScript syntax, taking on the most important concepts.

What you'll need

You don't need any special software to write JavaScript. All you need is a plain text editor and a web browser.

Code written in JavaScript must be executed from a document written in (X)HTML. There are three ways of doing this. You can place the JavaScript between <script> tags within the <head> of the document:

<!DOCTYPE html >
<html lang="en">
<head>
  <meta charset="utf-8"/>
  <title>Example</title>
  <script>
    JavaScript goes here...
  </script>
</head>
<body>
  Mark-up goes here... </body> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required