Skip to content

Instantly share code, notes, and snippets.

@aarongustafson
Created July 17, 2010 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarongustafson/479723 to your computer and use it in GitHub Desktop.
Save aarongustafson/479723 to your computer and use it in GitHub Desktop.
<?php
function example()
{
$a = $b = 0;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Serial value assignment and scope</title>
<script type="text/javascript">
(function(){
var a = b = 0;
})();
</script>
</head>
<body>
<h1>Serial variable assignment and scope test</h1>
<h2>Create a closure:</h2>
<pre><code class="js">(function(){
var a = b = 0;
})();</code></pre>
<p>Test for variables in the global scope:</p>
<ul>
<li>Test for <var>window.i</var>:
<script type="text/javascript">
try {
document.write( 'a is defined in the global namespace and has a value of ' + a );
}
catch ( e )
{
document.write( 'a is undefined in the global namespace' );
}
</script>
</li>
<li>Test for <var>window.j</var>:
<script type="text/javascript">
try {
document.write( 'b is defined in the global namespace and has a value of ' + b );
}
catch ( e )
{
document.write( 'b is undefined in the global namespace' );
}
</script>
</li>
</ul>
</body>
</html>
(function(){
var a = b = 0;
})();
(function(){
var a = 0, b = 0;
})();
(function(){
var a = 0, b = a;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment