The with Statement

The with statement sets the scope within a particular object. The syntax is as follows:


with (expression) 
   statement;

var qs = location.search.substring(1); 
var hostName = location.hostname;

The code above can be rewritten using the with statement:


with(location){ 
    var qs = search.substring(1); 
    var hostName = hostname; 
}

In strict mode, the with statement is not allowed and is considered a syntax error.

Home 
  JavaScript Book 
    Language Basics  

Statements:
  1. The if Statement
  2. The do...while Statement
  3. The while Statement
  4. The for Statement
  5. The for-in Statement
  6. Labeled Statements
  7. The break and continue Statements
  8. The with Statement
  9. The switch Statement