Convert to boolean

suggest change

Boolean(...) will convert any data type into either true or false.

Boolean("true") === true
Boolean("false") === true
Boolean(-1) === true
Boolean(1) === true
Boolean(0) === false
Boolean("") === false
Boolean("1") === true
Boolean("0") === true
Boolean({}) === true
Boolean([]) === true

Empty strings and the number 0 will be converted to false, and all others will be converted to true.

A shorter, but less clear, form:

!!"true" === true
!!"false" === true
!!-1 === true
!!1 === true
!!0 === false
!!"" === false
!!"1" === true
!!"0" === true
!!{} === true
!![] === true

This shorter form takes advantage of implicit type conversion using the logical NOT operator twice, as described in http://stackoverflow.com/documentation/javascript/208/boolean-logic/3047/double-negation-x

Here is the complete list of boolean conversions from the ECMAScript specification

Values that get converted to false as booleans are called falsy (and all others are called truthy). See http://stackoverflow.com/documentation/javascript/208/comparison-operations#remarks.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Variable coercion / conversion:
* Convert to boolean

Table Of Contents
11 Arrays
12 Objects
14 Classes
15 Variable coercion / conversion
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde