flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Harui <aha...@adobe.com>
Subject Re: [FalconJX] null vs undefined
Date Wed, 10 Feb 2016 23:22:13 GMT


On 2/10/16, 2:47 PM, "Harbs" <harbs.lists@gmail.com> wrote:

>One of the big use cases to use strict equality is with Numbers and
>Strings when you want to exclude 0 and empty strings.

Sure, but in my testing, checking against null with "==" works just as
well if the type is known.
 
>
>The reason this came up now is based on my work with E4X.
>
>If I’m reading the spec correctly, it differentiates between namespaces
>with prefixes which are undefined and prefixes which have an empty
>string. To test whether the prefix string is undefined or an empty
>string, I need strict equality, and I was not sure as to whether to test
>for null or undefined.

I think the first issue is the data type.  If you can expect undefined,
then the type should be "*" if null is a separate allowed value.
Otherwise I think if you use String and "==" you'll be ok.  Or does that
not work somewhere?

>
>I guess I can always initialize the prefix of namespaces as null. (i.e.
>private var _prefix:String = null;)That will cross-compile correctly.
>Right?

Yes, it should.

>
>Actually, I just did some tests with JS and it looks like I’m not totally
>clear on how JS handles null and undefined in comparisons:
>var a = "";
>alert(a==null)//false
>alert(""==null)//true

I did not get this in JSFiddle.

HTML:
<span id="out" />

JS:
    var foo;
		var bar = "0";
		var baz = 0;
		var empty = "";
		
    var s = "";
		s += (foo == null) ? "foo == null<br/>" : "foo != null<br/>";
		s += (bar == null) ? "bar == null<br/>" : "bar != null<br/>";
		s += (foo === null) ? "foo === null<br/>" : "foo !== null<br/>";
		s += (bar === null) ? "bar === null<br/>" : "bar !== null<br/>";
		s += (baz == null) ? "baz == null<br/>" : "baz != null<br/>";
		s += (baz === null) ? "baz === null<br/>" : "baz !== null<br/>";
		s += (empty == null) ? "empty == null<br/>" : "empty != null<br/>";
		s += (empty === null) ? "empty === null<br/>" : "empty !== null<br/>";
		s += ("" == null) ? "'' == null<br/>" : "'' != null<br/>";


		document.getElementById("out").innerHTML = s;



>
>var a = "";
>var b;
>alert(b==null);//true
>alert(b==undefined);//true
>alert(b=="");//false
>alert(b==a);//false

This is what I would expect.

-Alex

Mime
View raw message