Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

9 Whitespace

MDN: Grammar and types: Basics

For the most part, whitespace is ignored in JavaScript except around reserved words. Whitespace can be used to help make code more readable, but there are particular uses which can’t be ignored.

var say_hi = "Hello, world!";
varsay_hi = "Hello, world!";
Trace(say_hi);
Trace( say_hi );

In the above example:

  1. Line 1 will execute as expected.

  2. Line 2 will throw an error because var is a reserved word in JavaScript. Scripter will think there is already a variable called varsay_hi which does not exist.

  3. Lines 3 and 4 are both valid and will execute as expected.