with Statements

with statements establish default objects for sets of statements. JavaScript reviews unqualified names to determine whether the names are properties of the default object. If an unqualified name matches a property, the property is used in the statement; otherwise, a local or global variable is used.

with statement syntax:

with (object){
  statements
}

Example—Math is specified as the default object; the PI property and the cos and sin methods are referenced, but no object is specified for the references; therefore, Math is assumed to be the object of the references:

var a, x, y
var r=10   
with (Math) {
  a = PI * r * r
  x = r * cos(PI)
  y = r * sin(PI/2)
}