<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: ECMA-262-3 in detail. Chapter 2. Variable object.</title>
	<atom:link href="http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/feed/" rel="self" type="application/rss+xml" />
	<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/</link>
	<description>by Dmitry Soshnikov</description>
	<lastBuildDate>Sun, 13 May 2012 08:41:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-8179</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Thu, 27 Oct 2011 17:08:07 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-8179</guid>
		<description>@&lt;b&gt;Plamen Todorov&lt;/b&gt;

&lt;blockquote&gt;To summarize: The less we use the term variable, the less is the confusion.

I am curious, do you think such explanation is correct?&lt;/blockquote&gt;

Yes, it&#039;s a good explanation. After all, all of them are just &lt;em&gt;properties&lt;/em&gt; of &lt;/em&gt;something&lt;/em&gt; (either of a VO/AO, or an &lt;em&gt;environment&lt;/em&gt; in ES5, or a simple object).

Though, for simplicity a term &lt;em&gt;variable&lt;/em&gt; in casual talks (when it&#039;s not required to differentiate some deep details) of course can also be used.

Dmitry.</description>
		<content:encoded><![CDATA[<p>@<b>Plamen Todorov</b></p>
<blockquote><p>To summarize: The less we use the term variable, the less is the confusion.</p>
<p>I am curious, do you think such explanation is correct?</p></blockquote>
<p>Yes, it&#8217;s a good explanation. After all, all of them are just <em>properties</em> of something (either of a VO/AO, or an <em>environment</em> in ES5, or a simple object).</p>
<p>Though, for simplicity a term <em>variable</em> in casual talks (when it&#8217;s not required to differentiate some deep details) of course can also be used.</p>
<p>Dmitry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Plamen Todorov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-8146</link>
		<dc:creator>Plamen Todorov</dc:creator>
		<pubDate>Thu, 27 Oct 2011 00:12:34 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-8146</guid>
		<description>Dmitry, thanks for the great articles!

You wrote:

&lt;blockquote&gt;just create the new property (but not the variable) of the global object. “Not the variable” is not in the sense that it cannot be changed, but “not the variable” in concept of variables in ECMAScript&lt;/blockquote&gt;


In my view these variable-property discussions brings the most confusion among the developers.

I would replace them with following:

1. All we need is Data
2. Data is accessed in two ways via Identifiers and via Properties (both of them of Reference Type you are talking about)
3. JavaScript creates an identifier for each variable declaration, function declaration and function formal parameter. The identifiers are stored as properties in Variable Object. The identifiers could not be deleted.
4. JavaScript creates a property for each property declaration. Two ways of doing it:
	-&gt; p = 5, no var in front of it
	-&gt; var obj = {p: 5}
Properties does not affect the VO (except global properties, because VO === GO in Global Context). Properties could be deleted.

To summarize: The less we use the term variable, the less is the confusion.

I am curious, do you think such explanation is correct?
May be a bit over-simplified considering EcmaScript specification but still.....

//Plamen</description>
		<content:encoded><![CDATA[<p>Dmitry, thanks for the great articles!</p>
<p>You wrote:</p>
<blockquote><p>just create the new property (but not the variable) of the global object. “Not the variable” is not in the sense that it cannot be changed, but “not the variable” in concept of variables in ECMAScript</p></blockquote>
<p>In my view these variable-property discussions brings the most confusion among the developers.</p>
<p>I would replace them with following:</p>
<p>1. All we need is Data<br />
2. Data is accessed in two ways via Identifiers and via Properties (both of them of Reference Type you are talking about)<br />
3. JavaScript creates an identifier for each variable declaration, function declaration and function formal parameter. The identifiers are stored as properties in Variable Object. The identifiers could not be deleted.<br />
4. JavaScript creates a property for each property declaration. Two ways of doing it:<br />
	-&gt; p = 5, no var in front of it<br />
	-&gt; var obj = {p: 5}<br />
Properties does not affect the VO (except global properties, because VO === GO in Global Context). Properties could be deleted.</p>
<p>To summarize: The less we use the term variable, the less is the confusion.</p>
<p>I am curious, do you think such explanation is correct?<br />
May be a bit over-simplified considering EcmaScript specification but still&#8230;..</p>
<p>//Plamen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-6190</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Tue, 15 Mar 2011 17:13:29 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-6190</guid>
		<description>@&lt;b&gt;Luiz&lt;/b&gt;

&lt;blockquote&gt;Looks like a typo error to me. Shouldn’t it be “impossibility to remove variable”?&lt;/blockquote&gt;

Well, variables are also properties of something. This &quot;something&quot; is the variable/activation object. Attribute &lt;code&gt;{DontDelete}&lt;/code&gt; relates exactly to a property, it&#039;s the attribute of the property. So, it&#039;s not a typo, since, repeat, a variable is also a property but with (initially) with its special attributes. However, to avoid confusion, yes, fixed it to &quot;variable&quot;; thanks.

Dmitry.</description>
		<content:encoded><![CDATA[<p>@<b>Luiz</b></p>
<blockquote><p>Looks like a typo error to me. Shouldn’t it be “impossibility to remove variable”?</p></blockquote>
<p>Well, variables are also properties of something. This &#8220;something&#8221; is the variable/activation object. Attribute <code>{DontDelete}</code> relates exactly to a property, it&#8217;s the attribute of the property. So, it&#8217;s not a typo, since, repeat, a variable is also a property but with (initially) with its special attributes. However, to avoid confusion, yes, fixed it to &#8220;variable&#8221;; thanks.</p>
<p>Dmitry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luiz</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-6189</link>
		<dc:creator>Luiz</dc:creator>
		<pubDate>Tue, 15 Mar 2011 16:09:28 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-6189</guid>
		<description>&lt;blockquote&gt;&quot;Variables, in contrast with simple properties, have attribute {DontDelete}, meaning impossibility to remove property via the delete operator:&quot;&lt;/blockquote&gt;

Looks like a typo error to me. Shouldn&#039;t it be  &quot;impossibility to remove variable&quot;?</description>
		<content:encoded><![CDATA[<blockquote><p>&#8220;Variables, in contrast with simple properties, have attribute {DontDelete}, meaning impossibility to remove property via the delete operator:&#8221;</p></blockquote>
<p>Looks like a typo error to me. Shouldn&#8217;t it be  &#8220;impossibility to remove variable&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Oakes</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-4458</link>
		<dc:creator>Karl Oakes</dc:creator>
		<pubDate>Fri, 03 Dec 2010 11:30:35 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-4458</guid>
		<description>Excellent article, I knew about variable and function hoisting but was unaware of their order within the VO. Great to read a series of articles that get down to the metal of the language, which helps to clarify some of the more intricate features.</description>
		<content:encoded><![CDATA[<p>Excellent article, I knew about variable and function hoisting but was unaware of their order within the VO. Great to read a series of articles that get down to the metal of the language, which helps to clarify some of the more intricate features.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nag</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-3746</link>
		<dc:creator>nag</dc:creator>
		<pubDate>Mon, 18 Oct 2010 17:54:47 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-3746</guid>
		<description>thank you very much for such a detail elaboration.

-nag</description>
		<content:encoded><![CDATA[<p>thank you very much for such a detail elaboration.</p>
<p>-nag</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-3719</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Sat, 16 Oct 2010 15:11:17 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-3719</guid>
		<description>@&lt;b&gt;nag&lt;/b&gt;

&lt;blockquote&gt;I think catch() must be a type of function.&lt;/blockquote&gt;

No, it&#039;s a clause of the &lt;code&gt;try&lt;/code&gt; statement, it&#039;s not a function. However, yeah, &lt;code&gt;catch&lt;/code&gt; adds a special object, containing its argument (in this case -- &quot;foo&quot;) in the front of current scope chain, &lt;em&gt;shadowing&lt;/em&gt; a global &quot;foo&quot; Therefore, we can refer it during &lt;code&gt;catch&lt;/code&gt; block is running. After it ends, its special object is removed from the scope chain and again the global &quot;foo&quot; is available. You can &lt;a href=&quot;http://dmitrysoshnikov.com/ecmascript/chapter-4-scope-chain/#affecting-on-scope-chain-during-code-execution&quot; rel=&quot;nofollow&quot;&gt;find this case described in detail&lt;/a&gt; in the fours chapter, devoted a scope chain.

&lt;blockquote&gt;I tried eval(), which treats local variables as belonging to global scope.&lt;/blockquote&gt;

&lt;code&gt;eval&lt;/code&gt; works with the &lt;em&gt;calling&lt;/em&gt; context and uses the variable object and the scope chain exactly of the &lt;em&gt;calling&lt;/em&gt; context (i.e. the context, from which eval is called). Therefore, if a variable is created within &lt;code&gt;eval&lt;/code&gt;, it&#039;s created in the calling context; and if you call &lt;code&gt;eval&lt;/code&gt; from the global context, of course it creates a variable in the global context. This case is &lt;a href=&quot;http://dmitrysoshnikov.com/ecmascript/chapter-1-execution-contexts/#eval-code&quot; rel=&quot;nofollow&quot;&gt;described&lt;/a&gt; in the first chapter.

Notice however, that in the &lt;a href=&quot;http://dmitrysoshnikov.com/ecmascript/es5-chapter-2-strict-mode/&quot; rel=&quot;nofollow&quot;&gt;strict mode&lt;/a&gt; of ES5, &lt;code&gt;eval&lt;/code&gt; executes its code in the &lt;em&gt;sandbox environment&lt;/em&gt; and cannot create a variable in the calling context.

&lt;blockquote&gt;IE treats foo as global.&lt;/blockquote&gt;

IE&#039;s bug.

Dmitry.</description>
		<content:encoded><![CDATA[<p>@<b>nag</b></p>
<blockquote><p>I think catch() must be a type of function.</p></blockquote>
<p>No, it&#8217;s a clause of the <code>try</code> statement, it&#8217;s not a function. However, yeah, <code>catch</code> adds a special object, containing its argument (in this case &#8212; &#8220;foo&#8221;) in the front of current scope chain, <em>shadowing</em> a global &#8220;foo&#8221; Therefore, we can refer it during <code>catch</code> block is running. After it ends, its special object is removed from the scope chain and again the global &#8220;foo&#8221; is available. You can <a href="http://dmitrysoshnikov.com/ecmascript/chapter-4-scope-chain/#affecting-on-scope-chain-during-code-execution" rel="nofollow">find this case described in detail</a> in the fours chapter, devoted a scope chain.</p>
<blockquote><p>I tried eval(), which treats local variables as belonging to global scope.</p></blockquote>
<p><code>eval</code> works with the <em>calling</em> context and uses the variable object and the scope chain exactly of the <em>calling</em> context (i.e. the context, from which eval is called). Therefore, if a variable is created within <code>eval</code>, it&#8217;s created in the calling context; and if you call <code>eval</code> from the global context, of course it creates a variable in the global context. This case is <a href="http://dmitrysoshnikov.com/ecmascript/chapter-1-execution-contexts/#eval-code" rel="nofollow">described</a> in the first chapter.</p>
<p>Notice however, that in the <a href="http://dmitrysoshnikov.com/ecmascript/es5-chapter-2-strict-mode/" rel="nofollow">strict mode</a> of ES5, <code>eval</code> executes its code in the <em>sandbox environment</em> and cannot create a variable in the calling context.</p>
<blockquote><p>IE treats foo as global.</p></blockquote>
<p>IE&#8217;s bug.</p>
<p>Dmitry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nag</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-3717</link>
		<dc:creator>nag</dc:creator>
		<pubDate>Sat, 16 Oct 2010 13:04:30 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-3717</guid>
		<description>Dmitry,
&lt;b&gt;Excerpt from your last comment::&lt;/b&gt;
&lt;i&gt;
P.S.: actually, JS has some case of block-scope var, however, it’s not an explicit var, but the argument of the catch-clause:

var foo = 10;
try {  
  throw 20;  
} catch (foo) {  
  alert(foo); // 20  
}  
// again global  
alert(foo); // 10 
&lt;/i&gt;
The scenario elucidated above holds good in firefox.
IE treats &lt;b&gt;&lt;i&gt;foo&lt;/i&gt;&lt;b&gt; as global. 
Thus the result of final &lt;i&gt;alert(foo);&lt;/i&gt; statement is 20.

-nag</description>
		<content:encoded><![CDATA[<p>Dmitry,<br />
<b>Excerpt from your last comment::</b><br />
<i><br />
P.S.: actually, JS has some case of block-scope var, however, it’s not an explicit var, but the argument of the catch-clause:</p>
<p>var foo = 10;<br />
try {<br />
  throw 20;<br />
} catch (foo) {<br />
  alert(foo); // 20<br />
}<br />
// again global<br />
alert(foo); // 10<br />
</i><br />
The scenario elucidated above holds good in firefox.<br />
IE treats <b><i>foo</i></b><b> as global.<br />
Thus the result of final <i>alert(foo);</i> statement is 20.</p>
<p>-nag</b></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nag</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-3716</link>
		<dc:creator>nag</dc:creator>
		<pubDate>Sat, 16 Oct 2010 12:55:32 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-3716</guid>
		<description>Dimtry,

I think catch() must be a type of function.
I tried eval(), which treats local variables as belonging to global scope.

Thank you very much for explaining in such a great detail.

-nag</description>
		<content:encoded><![CDATA[<p>Dimtry,</p>
<p>I think catch() must be a type of function.<br />
I tried eval(), which treats local variables as belonging to global scope.</p>
<p>Thank you very much for explaining in such a great detail.</p>
<p>-nag</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#comment-3715</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Sat, 16 Oct 2010 10:48:22 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=546#comment-3715</guid>
		<description>@&lt;b&gt;nag&lt;/b&gt;

In some languages there is a &lt;em&gt;block-scope&lt;/em&gt; variables. Such variables are being removed after the scope of block ends.

For instance, in C:

[c]// global
int foo = 10;

if (true) {
  // local
  int foo = 20;
  printf(&quot;%d&quot;, foo); // 20
} // block ends, its scope too, including local &quot;foo&quot;

// again global
printf(&quot;%d&quot;, foo); // 10[/c]

In JavaScript (in current version of standard) there is no block-scope local variables; only -- function-scope local variables.

That means:

[js]// global
var foo = 10;

if (true) {
  var foo = 20;
  alert(foo); // 20
} // block ends, but &quot;foo&quot; wasn&#039;t local

alert(foo); // 20[/js]

After careful reading of this chapter, you should know, that &lt;em&gt;all&lt;/em&gt; variables are created on &lt;a href=&quot;http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#entering-the-execution-context&quot; rel=&quot;nofollow&quot;&gt;entering the context&lt;/a&gt; stage. This means, that second &lt;code&gt;var&lt;/code&gt; in the JS example above is ignored, because there is already a &quot;foo&quot; var (notice, that if the local var in if-statement block was named e.g. &quot;bar&quot;, it also would created on entering the context). And only then, at &lt;a href=&quot;http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#code-execution&quot; rel=&quot;nofollow&quot;&gt;code execution&lt;/a&gt; stage, there is just an assignment in the if-block to global &quot;foo&quot;.

P.S.: actually, JS has some case of block-scope var, however, it&#039;s not an explicit &lt;code&gt;var&lt;/code&gt;, but the argument of the &lt;code&gt;catch&lt;/code&gt;-clause:

var foo = 10;
[js]try {
  throw 20; 
} catch (foo) {
  alert(foo); // 20
}

// again global
alert(foo); // 10[/js]

Dmitry.</description>
		<content:encoded><![CDATA[<p>@<b>nag</b></p>
<p>In some languages there is a <em>block-scope</em> variables. Such variables are being removed after the scope of block ends.</p>
<p>For instance, in C:</p>
<pre class="brush: cpp; title: ;">// global
int foo = 10;

if (true) {
  // local
  int foo = 20;
  printf(&quot;%d&quot;, foo); // 20
} // block ends, its scope too, including local &quot;foo&quot;

// again global
printf(&quot;%d&quot;, foo); // 10</pre>
<p>In JavaScript (in current version of standard) there is no block-scope local variables; only &#8212; function-scope local variables.</p>
<p>That means:</p>
<pre class="brush: jscript; title: ;">// global
var foo = 10;

if (true) {
  var foo = 20;
  alert(foo); // 20
} // block ends, but &quot;foo&quot; wasn't local

alert(foo); // 20</pre>
<p>After careful reading of this chapter, you should know, that <em>all</em> variables are created on <a href="http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#entering-the-execution-context" rel="nofollow">entering the context</a> stage. This means, that second <code>var</code> in the JS example above is ignored, because there is already a &#8220;foo&#8221; var (notice, that if the local var in if-statement block was named e.g. &#8220;bar&#8221;, it also would created on entering the context). And only then, at <a href="http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/comment-page-1/#code-execution" rel="nofollow">code execution</a> stage, there is just an assignment in the if-block to global &#8220;foo&#8221;.</p>
<p>P.S.: actually, JS has some case of block-scope var, however, it&#8217;s not an explicit <code>var</code>, but the argument of the <code>catch</code>-clause:</p>
<p>var foo = 10;</p>
<pre class="brush: jscript; title: ;">try {
  throw 20;
} catch (foo) {
  alert(foo); // 20
}

// again global
alert(foo); // 10</pre>
<p>Dmitry.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

