<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx</link><description>First, the technical stuff. Here's a recent question I received about missing data in JScript. I&amp;#8217;ve seen it stated that in order to determine if a variable is undefined, you have to use if("undefined" == typeof(x)) I attended a presentation on JScript</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197313</link><pubDate>Mon, 26 Jul 2004 19:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197313</guid><dc:creator>Legion</dc:creator><description>Congratulations!  I hope to avoid that terrible fate myself ... but unless all the women I know are being insanely subtle (though after reading some of the mad crush advice, that's not out of the realm of possibility), I'm not in the &amp;quot;at risk&amp;quot; demographic.&lt;br&gt;&lt;br&gt;Curiosity now begs the question ... &amp;quot;What horrible fate befalls boys that propose marriage to the girls that don't want it?&amp;quot;  Hopefully it's something nicer than being beaten up and exiled to a desert island.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197402</link><pubDate>Mon, 26 Jul 2004 19:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197402</guid><dc:creator>Larry Osterman</dc:creator><description>Hey, Mazel Tov Eric!  May you guys have a long and wonderful life together.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197407</link><pubDate>Mon, 26 Jul 2004 19:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197407</guid><dc:creator>Shike Maffer</dc:creator><description>Congrats Eric!  Hope you and Leah will be very happy for years to come.&lt;br&gt;&lt;br&gt;Thanks for the insight into the === operator.  I had a student ask about this, in the light of the fact that JScript is not typed, how can you compare object types?  My response was for him sit down and get back to work on today's lesson :-) or something equally as non-educating.  I have sent him an email (he's since graduated) correcting my error.  Thanks again!</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197585</link><pubDate>Mon, 26 Jul 2004 20:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197585</guid><dc:creator>Dan Shappir</dc:creator><description>Congratulations Eric! As a ten year veteran I can honestly tell marriage is a good thing (my wife has yet to rescue me off a desert island, but she has baked me a cake).</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197586</link><pubDate>Mon, 26 Jul 2004 20:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197586</guid><dc:creator>Eric Lippert</dc:creator><description>&amp;gt; From step 3, I think this might allow for an exception&lt;br&gt;&lt;br&gt;I'm not following you.  Step 3 of GetBase can only be executed if step 1 returns a reference.  All references have a base object.  There's nothing in here that can produce an exception.&lt;br&gt;&lt;br&gt;Are you perhaps thinking of Step 3 of GetValue?  Sure, that can throw an exception, but step 3 of GetBase ensures that GetValue is never called with a null reference.&lt;br&gt;</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197595</link><pubDate>Mon, 26 Jul 2004 20:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197595</guid><dc:creator>Steve</dc:creator><description>Congrats!  You never fully realize the &amp;quot;can't live with them...&amp;quot; saying until you're married.  I wouldn't trade it for the world and I'm sure you'll feel the same way about yours.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197775</link><pubDate>Tue, 27 Jul 2004 01:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197775</guid><dc:creator>Nicholas Allen</dc:creator><description>Hey, congratulations on making the big move!&lt;br&gt;&lt;br&gt;As an interesting Internet confluence, today we got a bug report from someone that &amp;quot;1&amp;quot; != 1 when they specified JavaScript version 1.2.&lt;br&gt;&lt;br&gt;The original JavaScript had type insensitive equality and the final ECMA standard v1 had type insensitive equality.  However, Navigator 4 was based on a draft standard (along with a raft of Netscape extensions) and shipped with a type sensitive == and !=.  This was JavaScript version 1.2 (1.0 and 1.1 correspond to the previous Navigator 2 and 3 releases).  It lasted from late '96 more than a year until Navigator 4.5 was released.&lt;br&gt;&lt;br&gt;The === and !== were added in JavaScript 1.3 and regular equality was changed back to the type insensitive version.  Unless of course, you specifically ask for version 1.2.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197779</link><pubDate>Tue, 27 Jul 2004 01:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197779</guid><dc:creator>Eric Lippert</dc:creator><description>Thanks all for your kind congratulations.  &lt;br&gt;&lt;br&gt;Re: JavaScript 1.2 -- indeed! Though I had forgotten the exact details, I certainly recall my colleagues who were attending the committee meetings in 1997 describing a certain amount of kerfuffle around this misfeature of 1.2.  What a mess.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#197886</link><pubDate>Tue, 27 Jul 2004 05:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:197886</guid><dc:creator>secretGeek</dc:creator><description>congratulations eric!</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198337</link><pubDate>Tue, 27 Jul 2004 12:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198337</guid><dc:creator>sil</dc:creator><description>Useful info on ===, thanks. As a corollary, which of these is better, in the sense of &amp;quot;won't give an answer which is contrary to what I expect&amp;quot;?&lt;br&gt;&lt;br&gt;if (document.getElementById)&lt;br&gt;&lt;br&gt;or&lt;br&gt;&lt;br&gt;if (typeof document.getElementById != &amp;quot;undefined&amp;quot;)&lt;br&gt;&lt;br&gt;or&lt;br&gt;&lt;br&gt;if (typeof document.getElementById == 'function')&lt;br&gt;&lt;br&gt;as a way of detecting whether a particular function exists? I tend to use 1, but it's been suggested that 3 is better...&lt;br&gt;&lt;br&gt;Oh, and congrats on the engagement!</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198473</link><pubDate>Tue, 27 Jul 2004 15:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198473</guid><dc:creator>Eric Lippert</dc:creator><description>Well, the first says &amp;quot;is this property not null?&amp;quot;  The second says &amp;quot;is this property defined?&amp;quot;  The third says &amp;quot;is this property a function?&amp;quot;  &lt;br&gt;&lt;br&gt;Which question do you want to ask?</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198583</link><pubDate>Tue, 27 Jul 2004 16:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198583</guid><dc:creator>sil</dc:creator><description>Heh. That's sort of the point. What I want to ask is &amp;quot;does document.getElementbyId exist, and is it the DOM function that I'm expecting it to be?&amp;quot; Since, obviously, I can't ask that specifically, which of your three questions is least likely to give me an answer that differs from the answer to my ideal question? There isn't a clear answer to this, naturally; I'm more curious what you would use in that situation.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198632</link><pubDate>Tue, 27 Jul 2004 16:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198632</guid><dc:creator>Eric Lippert</dc:creator><description>&amp;gt; does document.getElementbyId exist&lt;br&gt;&lt;br&gt;That's easily done by any of the above, but the last is probably the most specific and therefore the most useful.&lt;br&gt;&lt;br&gt;&amp;gt; is it the DOM function that I'm expecting it to be?&lt;br&gt;&lt;br&gt;Hmm.  Under what circumstances would it not be?&lt;br&gt;&lt;br&gt;I'm getting the sneaking suspicion that there's a security question in here somewhere.  </description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198647</link><pubDate>Tue, 27 Jul 2004 17:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198647</guid><dc:creator>Stuart Updegrave</dc:creator><description>eric and leah -- &lt;br&gt;&lt;br&gt;many many congratulations! i love the dance party idea ... :) </description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198845</link><pubDate>Tue, 27 Jul 2004 18:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198845</guid><dc:creator>sil</dc:creator><description>Oh, I wasn't intending to pose a security question, really. At the moment, before I use any DOM code like document.getElementById() in a page, I bracket said code with if (document.getElementById). My question was more, &amp;quot;given the choice, which would you do?&amp;quot;</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198850</link><pubDate>Tue, 27 Jul 2004 18:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198850</guid><dc:creator>Eric Lippert</dc:creator><description>Got it.  Because I can think of three reasons why a method might not be there:&lt;br&gt;&lt;br&gt;1) Because you're maybe using some browser that doesn't support it.  In that case I'd recommend checking for browser version explicitly, etc.&lt;br&gt;&lt;br&gt;2) Because the property might accidentally be reset.  Then a simple check would suffice.&lt;br&gt;&lt;br&gt;3) Because the property might be deliberately reset by hostile code that you didn't write -- like a script injection attack.  In that case you have a very serious problem on your hands that would need careful threat modelling before we could begin to mitigate it.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198891</link><pubDate>Tue, 27 Jul 2004 19:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198891</guid><dc:creator>Nicholas Allen</dc:creator><description>Ok, so let's say malware.com has owned your document host object.  What do they need your script for?  They can inject or modify any content they want.  It seems like they already have all the keys at this point.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#198953</link><pubDate>Tue, 27 Jul 2004 19:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:198953</guid><dc:creator>Eric Lippert</dc:creator><description>Exactly!  That's why I wanted to make sure that the question wasn't actually a security question.  Determining whether any function actually does what you think it does is pretty much impossible if the environment is hostile, and it is pointless to try.&lt;br&gt;</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#200511</link><pubDate>Thu, 29 Jul 2004 08:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200511</guid><dc:creator>Mike Schinkel</dc:creator><description>Congrats on the engagement! May you two &amp;quot;live happily ever after!&amp;quot;</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#200896</link><pubDate>Thu, 29 Jul 2004 17:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:200896</guid><dc:creator>Sathyaish Chakravarthy</dc:creator><description>A hearty congratulations, Eric. Wish you a long, prosperous and blissful married life ahead.</description></item><item><title>=== in PHP</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#201612</link><pubDate>Fri, 30 Jul 2004 10:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:201612</guid><dc:creator>foxyshadis</dc:creator><description>=== is well known to any PHP programmer worth their salt. On the other hand, 6 years after inital implementation comments and questions about checking for type (or far more commonly, warnings about 'mysterious' failures when checking a return value for false when it can be int/string or false on failure, and the ugly workarounds for it) still regularly pop up, even from fairly knowledgeable people who never felt the need to learn how their language of choice differs from C/C++/Java. This and other background differences is probably one of the major pitfalls of giving an untyped language a familiar C family typed syntax.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#202186</link><pubDate>Fri, 30 Jul 2004 14:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:202186</guid><dc:creator>Roy Sharon</dc:creator><description>I think that the &amp;quot;undefined&amp;quot; thing has a more subtle behavior. Compare the following two programs.&lt;br&gt;&lt;br&gt;Program #1:&lt;br&gt;var foo;&lt;br&gt;if (foo === undefined) var bar = 1;&lt;br&gt;&lt;br&gt;Program #2:&lt;br&gt;if (foo === undefined) var bar = 1;&lt;br&gt;&lt;br&gt;Program #1 will run fine, resulting with bar==1. But program #2 will crash (try it!), because foo is undeclared when the if statement is reached. The *only* safe way to avoid this is doing:&lt;br&gt;if (typeof(foo) == &amp;quot;undefined&amp;quot;) var bar = 1;&lt;br&gt;&lt;br&gt;Program #2 may also be made to run by putting somewhere in it a declaration of foo:&lt;br&gt;var foo;&lt;br&gt;&lt;br&gt;This way, when the if statement is reached, foo is already declared, and is equal to undefined. &lt;br&gt;&lt;br&gt;BTW, declaring foo does not change its value, so you can safely do it even if you're not sure whether foo was previously declared. The only concern here is that declaring it inside some scope (such as a function), will make it a local variable, overriding a variable with the same name from a surrounding scope.&lt;br&gt;&lt;br&gt;BTW, there is a nice idiom that uses this technique to add a default value in case foo is undefined:&lt;br&gt;&lt;br&gt;if (foo === undefined) var foo = 3;&lt;br&gt;&lt;br&gt;The if statement will not cause a crash, because the parser collects all var declarations before executing the script, so foo is already declared when the if is reached.</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#202321</link><pubDate>Fri, 30 Jul 2004 16:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:202321</guid><dc:creator>Eric Lippert</dc:creator><description>Excellent point, Roy.  I hadn't considered the fact that typeof does not activate the &amp;quot;undeclared variable&amp;quot; logic.</description></item><item><title>How Do Script Engines Implement Object Identity?</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#412200</link><pubDate>Tue, 26 Apr 2005 19:55:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:412200</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>I've talked a few times in this blog about the semantics of the equality operators in various languages....</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#4419129</link><pubDate>Thu, 16 Aug 2007 21:24:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4419129</guid><dc:creator>Mark</dc:creator><description>&lt;p&gt;I think that the code &lt;/p&gt;
&lt;p&gt;if(x === undefined)&lt;/p&gt;
&lt;p&gt; is actually testing that the variable named &amp;quot;x&amp;quot; is strictly equal to the variable named &amp;quot;undefined&amp;quot;. undefined is not a keyword, so a declaration such as &lt;/p&gt;
&lt;p&gt;var undefined = true; &lt;/p&gt;
&lt;p&gt;is perfectly legal. This declaration would obviously break the strict equality test, so I think that &lt;/p&gt;
&lt;p&gt;if(typeof(x) == &amp;quot;undefined&amp;quot;)&lt;/p&gt;
&lt;p&gt;is really the only &amp;quot;correct&amp;quot; way to do this test.&lt;/p&gt;
&lt;p&gt;Sorry to post a comment so out of date, but I just recently discovered your blog and have been enjoying reading through your old posts.&lt;/p&gt;
</description></item><item><title>re: JScript Equality Operators, plus More On Mad Crushes</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#4419971</link><pubDate>Thu, 16 Aug 2007 22:07:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4419971</guid><dc:creator>Eric Lippert</dc:creator><description>&lt;p&gt;You are correct, and I should have called that out in the post.&lt;/p&gt;
</description></item><item><title>script magazine  &amp;raquo; Blog Archive   &amp;raquo; ???????????????????? ???????? ????????????</title><link>http://blogs.msdn.com/ericlippert/archive/2004/07/26/197302.aspx#4895303</link><pubDate>Thu, 13 Sep 2007 18:13:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4895303</guid><dc:creator>script magazine  » Blog Archive   » ???????????????????? ???????? ????????????</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://script.shabunc.org/?p=35"&gt;http://script.shabunc.org/?p=35&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>