0

I'm trying to manipulate the view of a web messaging system and the default view is a blank object, {}. I used an ng-show="data.currentView == {}" in my AngularJS script to check if it is currently the default view, but it never showed. Then I tried this in my Javascript Console in Chrome:

var data = {}
console.log(data == {})
//Logs false
console.log(data === {})
//Logs false

Why is that statement returning false?

q.Then
  • 2,743
  • 1
  • 21
  • 31

2 Answers2

4

You are testing to see if two objects are the same object, not if they are identical objects.

See the specification:

If Type(x) is the same as Type(y), then … Return true if x and y refer to the same object. Otherwise, return false.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

You are comparing references with objects, so they are never equal. A good way would be:

Object.keys(data.currentView).length == 0
juvian
  • 15,875
  • 2
  • 37
  • 38