Syntax Basics
Prev Chapter 2. JavaScript Basics Next

Syntax Basics

Understanding statements, variable naming, whitespace, and other basic JavaScript syntax.

Example 2.1. A simple variable declaration

var foo = 'hello world';

Example 2.2. Whitespace has no meaning outside of quotation marks

var foo =         'hello world';

Example 2.3. Parentheses indicate precedence

2 * 3 + 5;    // returns 11; multiplication happens first
2 * (3 + 5);  // returns 16; addition happens first

Example 2.4. Tabs enhance readability, but have no special meaning

var foo = function() {
    console.log('hello');
};


Copyright Rebecca Murphey, released under the Creative Commons Attribution-Share Alike 3.0 United States license.


Prev Up Next
Chapter 2. JavaScript Basics Home Operators