Chapter 2

Understanding Syntax

Just as spoken languages have rules (called grammar), computer programming languages have rules (called syntax). When you understand the basic rules of speaking JavaScript, it actually looks similar to English.

If you thought that your teacher correcting you when you say “ain’t” was strict, wait until you see how strict JavaScript is! It won’t even listen to a thing you say if you make certain kinds of syntax errors.

In this chapter, you learn the basics of JavaScript syntax and how to avoid being scolded by the syntax police!

image

Saying Precisely What You Mean

In order to be compiled correctly into machine language instructions, programs need to be written very precisely.

remember Chapter 1 explains what a program is and how programs are translated into machine language using the process called compilation.

As a programmer, your job is to think about the big picture of what you want the program to do, and then break it down into bite-size steps that can be accomplished by the computer without errors. For example, if you wanted to ask a robot to go downstairs and get you a sandwich, you might start your instructions like this:

  1. Rotate head toward stairs.
  2. Use visual sensors to look for obstacles.
  3. If an obstacle is found, determine what it is.
  4. If the obstacle ...

Get JavaScript For Kids For Dummies 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.