7

I have strange situation - here is Javascript code - and in NetBeans IDE 8.0 I see an alert "Expected a conditional expression and instead saw an assignment":

var elem;
var a = 0;
while ((elem = document.getElementById('id-' + a)) !== null) {
    //Some code
    a++;
}

But code works fine. Maybe this is some bug in Netbeans IDE 8.0?

Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117

1 Answers1

8

The code is fine. The IDE's warning is because usually a comparison (==) is made, but sometimes an assignment (=) is what is actually wanted. It's to catch mistakes made by missing an equals sign.

Here, you set the elem variable, and at the same time, compare it to null.

Scimonster
  • 32,893
  • 9
  • 77
  • 89