Parses the string argument as a boolean
. The boolean
returned represents the value true
if the string argument is not null
and is equal, ignoring case, to the string "true"
.
When the Boolean.parse function is called with a string argument the following steps are taken:
- If Type(string) is not
"string"
- Return
false
- Return
- Let normalizedString be the result of applying
String.prototype.toLowerCase
on the string - If normalizedString is
"true"
- Return
true
- Return
- Return
false
Boolean.parse('true'); // true
Boolean.parse('false'); // false
// In contrast with problematic:
Boolean('false'); // true
Storages which doesn't support actual boolean values at serialization, and only have string-based value types. Example: Node's env
arguments.
So many issues with a so small proposal:
Number.parseInt
,Number.parseFloat
,Date.parse
,JSON.parse
, and pretty much every method that expects a string.True
,TRUE
, etc, as a valid variant oftrue
. There is no clear reason to innovate in that regard. Otherwise, one should consider recognisingyes
.Number.parseInt
,Number.parseFloat
,Date.parse
, andJSON.parse
ignore leading and trailing spaces, contrarily to the proposedBoolean.parseBoolean
.false
forBoolean.parseBoolean("foo")
. For exampleNumber.parseInt
,Number.parseFloat
andDate.parse
returnNaN
for unrecognised string, andJSON.parse
throws an error.