http://stackoverflow.com/questions/263965/how-can-i-convert-a-string-to-boolean-in-javascript

The first answer from the answer list:

You should probably be cautious about using these two methods for your specific needs:

var myBool =Boolean("false");// == true

var myBool =!!"false";// == true

Any string which isn't the empty string will evaluate to true by using them. Although they're the cleanest methods I can think of concerning to boolean conversion, I think they're not what you're looking for.

About the way you suggested, you could make it stricter by using the identity operator (===), which doesn't make any implicit type conversions when the compared variables have different types, instead of the equality operator (==), which does:

var isTrueSet =(myValue ==='true');

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2021-10-28
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2021-07-21
相关资源
相似解决方案