joshtynjala opened a new issue #78: Assign to Boolean variable does not convert 
to true or false, breaking loose comparison with ==
URL: https://github.com/apache/royale-compiler/issues/78
 
 
   Allowing boolean to store anything except `true` and `false` breaks loose 
comparison with the `==` operator. That's much more serious than breaking 
strict comparison with the `===` operator!
   
   ``` as3
   var obj:Object = {};
   var bool1:Boolean = obj;
   var bool2:Boolean = true;
   
   if(bool) //works
   {
   }
   
   if(bool1 == bool2) //fails!
   {
   }
   ```
   
   To coerce a value to boolean, we can use `!!` in JavaScript:
   
   ``` js
   var obj = {};
   var bool1 = !!obj; //true
   ```
   
   This coerces to `true` with any type of object, and also coerces to `false` 
for things like `null` and `undefined`.
   
   Initializing a boolean with another boolean (or an expression that resolves 
to boolean) doesn't require coercion.
   
   Additionally, similar to how `int` and `uint` default to `0` when there's no 
initializer, `Boolean` variables should default to `false` unless initialized 
with another value.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to