1

Why is that:

var bla = {
    "1":"1",
    "2":"2"    
}

console.log(bla === true) 

is false ?

http://jsfiddle.net/nottinhill/jdxvnea1/

Nabil Kadimi
  • 10,078
  • 2
  • 51
  • 58
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147

4 Answers4

4

That's because bla is an object not a boolean.

console.log(typeof bla === 'object') //logs true

check this Q/A for more help on that

Community
  • 1
  • 1
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
3

By using === you are comparing without doing a type conversion, so variable with different types will never be equal.

> bla = {"1": "1", "2": "2"}

> bla == true
=> false

> bla === true
=> false

> bla === false
=> false

> Boolean(bla) === true        // Do it like this
=> true
Nabil Kadimi
  • 10,078
  • 2
  • 51
  • 58
1

Your bla is an object and false is boolean.

  • Strict equality ===

The identity operator returns true if the operands are strictly equal (see above) with no type conversion.

  • Equality ==

The equality operator converts the operands if they are not of the same type, then applies strict comparison. If either operand is a number or a boolean, the operands are converted to numbers if possible; else if either operand is a string, the string operand is converted to a number if possible. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.

Sources:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators

Beri
  • 11,470
  • 4
  • 35
  • 57
0

you cannot equate a object to a boolean. you can do with the object index or check for the existence of the object like this

console.log(bla[1] == true)
or 
if(bla)  { console.log(true); }