Consider this code:
<script>var foo = 'bar';</script>
<div id='isolated'>
<script>console.log(foo)</script>
</div>
This will return 'bar'
to the console. However I'd like for foo
and any other variables declared outside #isolated
to be undefined
from within it.
How can this be achieved? A cross-browser, lightweight and native solution would be preferable.