Why top level properties behaving differently ?http://forums.asp.net/t/1657585.aspx/1?Why+top+level+properties+behaving+differently+Sat, 26 Feb 2011 06:04:44 -050016575854320161http://forums.asp.net/p/1657585/4320161.aspx/1?Why+top+level+properties+behaving+differently+Why top level properties behaving differently ? <p>HI,</p> <p>please consider this javaScript code:</p> <p>&nbsp;</p> <pre class="prettyprint">&lt;html&gt; &lt;head&gt; &lt;script&gt; var foo='value1'; Object.foo1='value2'; alert(foo&#43;' '&#43;foo1); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&quot;mydiv&quot;&gt; In Div &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p>I have created two properties foo and foo1. Since they are declared at top level they both are actually properties of Object.While accessing these properties in alert function then why i am getting error that foo1 is undefined ? Why at the same time foo is accessable but foo1 is unaccessable if both are properties belonging to Object ?</p> 2011-02-26T04:46:36-05:004320217http://forums.asp.net/p/1657585/4320217.aspx/1?Re+Why+top+level+properties+behaving+differently+Re: Why top level properties behaving differently ? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>shyam_oec</h4> I have created two properties foo and foo1. Since they are declared at top level they both are actually properties of Object.While accessing these properties in alert function then why i am getting error that foo1 is undefined ? Why at the same time foo is accessable but foo1 is unaccessable if both are properties belonging to Object ?</blockquote> <p></p> <p>hi, I think you have do wrong way</p> <p>you can do this way</p> <p><pre class="prettyprint">&lt;script type=&quot;text/javascript&quot;&gt; var foo = &quot;value1&quot;; Object.foo1 = &quot;value2&quot;; alert(foo &#43; ' ' &#43; Object.foo1); &lt;/script&gt;</pre> </p> 2011-02-26T06:04:44-05:00