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 basically this is the equivalent of
/^true$/i.test(str)
?I'd also be horrified by a
Boolean.parseBoolean(1)
that returnsfalse
.