# Boolean "false" equals true

**URL:** <https://forum.kirupa.com/t/boolean-false-equals-true/332106>\
**Category:** web dev\
**Created:** [January 30, 2014, 12:38pm UTC](https://forum.kirupa.com/t/boolean-false-equals-true/332106 "2014-01-30T12:38:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lnsiu](https://avatars.discourse-cdn.com/v4/letter/l/9fc29f/32.png) [@lnsiu](https://forum.kirupa.com/u/lnsiu)\
**Post date:** [January 30, 2014, 12:38pm UTC](https://forum.kirupa.com/t/boolean-false-equals-true/332106/1 "2014-01-30T12:38:35Z")

</div>

I have a string returned from a function and number works well, because it is possible to cast a number with Number();  
But for a boolean, this seems not to work?

Is it really necessary to parse the string “true” and “false” like this?

```auto

[FONT=Monaco][COLOR=#931a68]function[/COLOR] setSettings(result)[/FONT]
[FONT=Monaco]{[/FONT]
[FONT=Monaco] [COLOR=#931a68]var[/COLOR] res = result.split([COLOR=#3933ff]','[/COLOR]);[/FONT]
[COLOR=#4E9072][FONT=Monaco]//alert(res);[/FONT][/COLOR]
[FONT=Monaco] document.querySelector([COLOR=#3933ff]"#tilewidth"[/COLOR]).value = Number(res[0]);[/FONT]
[FONT=Monaco] document.querySelector([COLOR=#3933ff]"#tileheight"[/COLOR]).value= Number(res[1]);[/FONT]
[FONT=Monaco] document.querySelector([COLOR=#3933ff]"#fileprefix"[/COLOR]).value= res[2];[/FONT]
[FONT=Monaco] document.querySelector([COLOR=#3933ff]"#addlayer"[/COLOR]).checked= fBoolean(res[3]);[COLOR=#4e9072]//[/COLOR][/FONT]
[FONT=Monaco] document.querySelector([COLOR=#3933ff]"#foldername"[/COLOR]).value= res[4];[/FONT]
[FONT=Monaco] document.querySelector([COLOR=#3933ff]"#isretina"[/COLOR]).checked= fBoolean(res[5]);[COLOR=#4e9072]//[/COLOR][/FONT]
[FONT=Monaco] document.querySelector([COLOR=#3933ff]"#notlocalfolder"[/COLOR]).checked= fBoolean(res[6]);[COLOR=#4e9072]//[/COLOR][/FONT]
[FONT=Monaco]}[/FONT]
[FONT=Monaco]
[/FONT]
[FONT=Monaco][COLOR=#931a68]function[/COLOR] fBoolean(str)[/FONT]
[FONT=Monaco]{[/FONT]
[FONT=Monaco] [COLOR=#931a68]if[/COLOR](str==[COLOR=#3933ff]"true"[/COLOR])[/FONT]
[FONT=Monaco] {
[/FONT][COLOR=#931A68][FONT=Monaco] return true[COLOR=#000000];[/COLOR][/FONT][/COLOR]
[FONT=Monaco] }[/FONT]
[FONT=Monaco] [COLOR=#931a68]else[/COLOR] [COLOR=#931a68]if[/COLOR](str == [COLOR=#3933ff]"false"[/COLOR])[/FONT]
[FONT=Monaco] {
[/FONT][COLOR=#931A68][FONT=Monaco] return false[COLOR=#000000];[/COLOR][/FONT][/COLOR]
[FONT=Monaco] }[/FONT]
[FONT=Monaco]}[/FONT]

```
