Computer >> Computer tutorials >  >> Programming >> Javascript

How do I compare String and Boolean in JavaScript?


To compare string and Boolean in JavaScript, let us see the following examples. It returns true −

false == "0"; //true
true == "1"; //true
false == ""; //true

The followings returns false −

false == "false"; //false
true == "true"; //false

In addition, try the following example too −

var data = true;
data === "true" //false
String(data) === "true" //true