You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@royale.apache.org by GitBox <gi...@apache.org> on 2019/02/06 22:52:55 UTC

[GitHub] joshtynjala opened a new issue #78: Assign to Boolean variable does not convert to true or false

joshtynjala opened a new issue #78: Assign to Boolean variable does not convert to true or false
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 strict comparison with the `===` operator failing!
   
   ``` 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 works with any type of object, and also 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:
users@infra.apache.org


With regards,
Apache Git Services