jskatas.org Continuously Learn JavaScript. Your Way.

Type conversion: to boolean

How do different types convert to a boolean?

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

Type conversion - to boolean

  • undefined converts to false
  • null converts to false

Boolean

  • new Boolean(true) equals true
  • Boolean(false) converts to false

Number

  • +0 converts to false
  • -0 converts to false
  • NaN converts to false
  • 42 converts to true
  • -23 converts to true

String

  • an empty string converts to false
  • an NOT-empty string converts to true

Object

  • an empty Object converts to true
  • any other Object converts to true