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">
  <meta charset="utf-8"/>
    JavaScript goes here...
  Mark-up goes here... </body> ...

Get DOM Scripting: Web Design with JavaScript and the Document Object Model, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.