Hosting Solutions
mobile_logo Table of Contents


The with statement makes an object govern a segment of code. It can be used to reduce code that might refer to an object many times.

Syntaxwith ( object ) { ... }
with ( navigator ) { var str = language + "<hr>" + platform + "<hr>" + userAgent; } document.write( str ); Normally that line of code would be much bulkier: var str = navigator.language + "<hr>" + navigator.platform + "<hr>" + navigator.userAgent; document.write( str ); Now imagine you had many more lines of code that refer to the navigator object. The reduction of code in that segment would be significant in that case.



breakconstcontinuedo whileforfor inif elselabelreturnswitchtry catchvarwhilewith