JavaScript Variable coercion/conversion Converting a string to a boolean

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

To convert a string to boolean use

Boolean(myString)

or the shorter but less clear form

!!myString 

All strings except the empty string (of length zero) are evaluated to true as booleans.

Boolean('') === false   // is true
Boolean("") === false   // is true
Boolean('0') === false  // is false
Boolean('any_nonempty_string') === true // is true


Got any JavaScript Question?