According to this : http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9f.html Quote:
An untyped variable is not the same as a variable of type Object. The key difference is that untyped variables can hold the special value undefined , while a variable of type Object cannot hold that value.
However when I test it as :
var objTest:Object = 123;
var untypedTest:* = 123;
objTest = undefined;
untypedTest = undefined;
//This is understandable but why was the assignment even allowed?
trace(objTest); // prints null
trace(untypedTest); // prints undefined
objTest=null;
untypedTest = null;
//This is also understandable ... both can store null
trace(objTest); // prints null
trace(untypedTest); // prints null
//If they are null whey are they being equal to undefined?
if(objTest==undefined)
trace("obj is undefined");
if(untypedTest==undefined)
trace("untyped is undefined");
//Because null is same as undefined!
if(null==undefined)
trace("null is same as undefined?");
Two questions:
Definition: Null: It is the intentional absence of the value. It is one of the primitive values of JavaScript. Undefined: It means the value does not exist in the compiler.
Unassigned variables are initialized by JavaScript with a default value of undefined. Here as the variable is declared but not assigned to any value, the variable by default is assigned a value of undefined. On the other hand, null is an object. It can be assigned to a variable as a representation of no value.
Null is pointing to nothing in memory. Undefined is a variable that has not been assigned any value. Lastly, undeclared is a variable that has not been properly declared using const, var, or let.
In JavaScript, undefined is a type, whereas null an object. It means a variable declared, but no value has been assigned a value. Whereas, null in JavaScript is an assignment value.
Some samples of that:
var i:int = NaN;
trace (i); // 0
Or:
var b:Boolean = null;
trace(b); // false
So when you're assigning undefined
to Object
instance Flash converts it to null
the same way.
Boolean
. You can use strict comparison to have false
:
if(null === undefined)
trace("Never traced: null is not the same as undefined!");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With