-2
'' == false // true
' ' == false // true
if ('') {
  // this code is not run
}
if (' ') {
  // this code is run
}

As you can see, there are interesting results. The empty string is treated as falsy, as we already know. However, whitespace strings are treated as truthy or falsy, depending on the situation.

msm082919
  • 617
  • 8
  • 24
  • The "conversion" to truthy or falsy is not the same as an `==` comparison to `true` or `false`. – Pointy Jul 28 '18 at 15:57

2 Answers2

0

You can see the link posted in your question about toBoolean behavior. Another interesting tidbit;javascript has another comparison operator === that checks for value and type

'' == false // true
'' === false // false
0

A blank String is false.

console.log(' '==true);
console.log(''==true);

This is often the problem with the == operator; it attempts to coerce the types of the objects it is comparing to be equal. If you use the === operator, it will not attempt type coercion.

console.log(''===false);
Unmitigated
  • 76,500
  • 11
  • 62
  • 80