With in JavaScript

With Statement provides short hand to access most frequently accessed objects. With statement has many drawbacks and it can be avoided

Object 1 and Object 2 Can be accessed
<script type="text/javascript">
parent.child.grandchild.object1 = true;
parent.child.grandchild.object2 = 10;
</script>


But using a With Statement we can access it in following way,
<script type="text/javascript">
with(parent.child.grandchild){
object1=true;
object2=false;
}
</script>


Disadvantages of using With Statement
1. It is difficult to update a Global Variable inside a With Statement
2. Code readability is very low, as the User will not understand which object gets changed.

The Alternative of With Statement is to define a Variable
<script type="text/javascript">
var key = parent.child.grandchild ;
key.object1=true;
key.object2=false;
</script>