<p><a href="http://www.stackoverflow.com/questions/61088/hidden-features-of-javascript#61118">Alan Storm's comments</a> in response to my answer regarding the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with" rel="noreferrer"><code>with</code> statement</a> got me thinking. I've seldom found a reason to use this particular language feature, and had never given much thought to how it might cause trouble. Now, I'm curious as to how I might make effective use of <code>with</code>, while avoiding its pitfalls.</p>

<p>Where have you found the <code>with</code> statement useful?</p>

Visual Basic.NET has a similar
```
With
```
statement. One of the more common ways I use it is to quickly set a number of properties. Instead of:
```
```
someObject.Foo = ''
someObject.Bar = ''
someObject.Baz = ''
```
```
, I can write:
```
```
With someObject
    .Foo = ''
    .Bar = ''
    .Baz = ''
End With
```
```
This isn't just a matter of laziness. It also makes for much more readable code. And unlike JavaScript, it does not suffer from ambiguity, as you have to prefix everything affected by the statement with a
```
.
```
(dot). So, the following two are clearly distinct:
```
```
With someObject
    .Foo = ''
End With
```
```
vs.
```
```
With someObject
    Foo = ''
End With
```
```
The former is
```
someObject.Foo
```
; the latter is
```
Foo
```
in the scope
outside
```
someObject
```
.
I find that JavaScript's lack of distinction makes it far less useful than Visual Basic's variant, as the risk of ambiguity is too high. Other than that,
```
with
```
is still a powerful idea that can make for better readability.