Provide some examples of non-bulean value coercion to a boolean one

Technology CommunityCategory: JavaScriptProvide some examples of non-bulean value coercion to a boolean one
VietMX Staff asked 3 years ago

The question is when a non-boolean value is coerced to a boolean, does it become true or false, respectively?

The specific list of “falsy” values in JavaScript is as follows:

  • "" (empty string)
  • 0-0NaN (invalid number)
  • nullundefined
  • false

Any value that’s not on this “falsy” list is “truthy.” Here are some examples of those:

  • "hello"
  • 42
  • true
  • [ ][ 1, "2", 3 ] (arrays)
  • { }{ a: 42 } (objects)
  • function foo() { .. } (functions)