How do I compare String and Boolean in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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
Published on 18-Jan-2018 13:05:41