Alex Rivera | Logout

How do I compare string and boolean in Javascript?

Asked 2011-04-14T05:49:26.890
24

I got the Json "false" from server. I respond as bool but it's Json so it's in browser type is String instead of bool.

So if I run (!data) whenever I want to check "false" == false then they not worked.

So how can I parse bool from String in JavaScript then?

"true" == true and "false" == false. Then the code (!data) can check what it is [true and false]

Edit
Report

1 Answer

4

Try expression data == "true"

Tests:

data = "false" -- value will be false

date = "true" -- value will be true

Also, fix your JSON. JSON can handle booleans just fine.

answered 2011-04-14T05:54:07.027

Your Answer