<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Calhoun&#039;s Blog &#187; let</title>
	<atom:link href="http://davidbcalhoun.com/tag/let/feed" rel="self" type="application/rss+xml" />
	<link>http://davidbcalhoun.com</link>
	<description>Just another blog</description>
	<lastBuildDate>Mon, 07 May 2012 02:06:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>JavaScript Tidbit: Block scope with &#8220;let&#8221;</title>
		<link>http://davidbcalhoun.com/2009/javascript-tidbit-block-scope-with-let</link>
		<comments>http://davidbcalhoun.com/2009/javascript-tidbit-block-scope-with-let#comments</comments>
		<pubDate>Tue, 15 Sep 2009 08:06:49 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[1.7]]></category>
		<category><![CDATA[block scope]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[let]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=23</guid>
		<description><![CDATA[JavaScript has functional scope. Meaning that if you (properly) define variables within functions, those variables remain accessible only inside the function. Block scope, on the other hand, defines scope within a block of code, usually defined by braces. JavaScript now has block scope as of version 1.7, which means it&#8217;s available in these browsers: Firefox [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript has <strong>functional scope</strong>.  Meaning that if you (properly) define variables within functions, those variables remain accessible only inside the function.</p>
<p><strong>Block scope</strong>, on the other hand, defines scope within a block of code, usually defined by braces.  JavaScript now has block scope as of version 1.7, which means it&#8217;s available in these browsers:</p>
<ul>
<li>Firefox 2+</li>
</ul>
<p>Block scope is enabled in JavaScript with the use of &#8220;let&#8221;:</p>
<pre name="code" class="JScript">let(x=100) {
    alert(x);
};</pre>
<p>It also works perfectly well on one line, without the use of braces:</p>
<pre name="code" class="JScript">let(x=100) alert(x);</pre>
<p>Note that we can define global variables with the same name outside the block scope and the variables won&#8217;t interfere with each other:</p>
<pre name="code" class="JScript">x = 200;
let(x=100) alert(x);
alert(x);
// result: 100, 200
</pre>
<p>Note that there&#8217;s a slight caveat &#8211; not only is this not available in any version of IE, but it also requires a special script type declaration in order to work (at least for Firefox): <strong>type=&#8221;text/javascript;version=1.7&#8243;</strong></p>
<p>References:<br />
<a href=" http://en.wikipedia.org/wiki/JavaScript#Versions">JavaScript Versions</a><br />
<a href="http://www.youtube.com/watch?v=0LKDImgRfrg#t=32m2s">Video: Best Practices in Javascript Library Design (John Resig)</a><br />
<a href="https://developer.mozilla.org/en/New_in_JavaScript_1.7">New in JavaScript 1.7</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/javascript-tidbit-block-scope-with-let/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

