Skip to content

Instantly share code, notes, and snippets.

@andreyp
Created September 3, 2014 11:30
Show Gist options
  • Save andreyp/b555737a75cd1cb20777 to your computer and use it in GitHub Desktop.
Save andreyp/b555737a75cd1cb20777 to your computer and use it in GitHub Desktop.
Как же так получается???
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
@spoof
Copy link

spoof commented Sep 3, 2014

по возможности избейгайте этого

@emera1d
Copy link

emera1d commented Sep 3, 2014

При двойном знаке равно происходит приведение типов. Непустая строка приводится в true. Равносильно:
Boolean(a) == true // true

И, да, "по возможности избейгайте этого".

@snutworks
Copy link

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