Boolean object in javascript returns true for false

I have a little problem.

I have situations where my ajax calss return a string.

sometimes this string is "false" I want to always convert this string value to a boolean I tried: new Boolean (thatValue)

but it returns true even for "false" as paremter

Is there anyway to solve this? except that I am writing my own custom function that will return false if "flase"? ..

Thank you

+3
source share
2 answers

The best way to do this you have already described:

if(value === 'true') {
  //do something
}

Or:

if(value !== 'false') {
  //do something
}

JavaScript, , true boolean, "false".

, - :

var myBool = value !== "false";
+3

, , "". :

thatValue == "false" ? false : true
+3

Source: https://habr.com/ru/post/1756739/


All Articles