Created
September 3, 2014 11:30
-
-
Save andreyp/b555737a75cd1cb20777 to your computer and use it in GitHub Desktop.
Как же так получается???
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = '0'; | |
var b = '1'; | |
a == true | |
//false | |
a == false | |
//true | |
b == true | |
//true | |
b == false | |
//false | |
if (a){console.log(a);} | |
//0 | |
if (b){console.log(b);} | |
//1 |
При двойном знаке равно происходит приведение типов. Непустая строка приводится в true. Равносильно:
Boolean(a) == true // true
И, да, "по возможности избейгайте этого".
public function parseBoolean(s:String):Boolean {
var result:Boolean;
if (s == 'true') {
result = true;
} else if (s == 'false') {
result = false;
} else {
result = Boolean(parseInt(s));
}
return result;
}
такой день
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
по возможности избейгайте этого