JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




With Statement Code


Tutorials Javascript

Topic

How to use with statement in javascript?
Using many functions of an object in easiest way?



Explanation
        "with" statement is used when numerous function of an object is used or a function of an object is to be used numerous times.

Syntax:
with(object)
{
     // Calling the functions or methods of the object
}


For this example we will use the object "document" and its methods (functions) "write" and attribute "title".
Example Code:
<script language="javascript">
with(document)
{
write(" inside with statement <br>");
write(" using with(object) we can call its functions directly <br>");
write (" TITLE -"+title);
}
</script>


Result:

In the above example you can clearly see that the write function is executed numerous times with out calling document.write() and also title (document.title) is called. You can use any objects with "with" statement. e.g: date, math, etc. You will know more about these objects in later part of the tutorial.





A Note
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

Other Links

web hosting