App lab is giving a yellow triangle and recommending "===" rather than "=="


#1

For several of my students’ code, app lab puts a yellow (warning) triangle and recommends they use “===” for comparison rather than “==”. Is this a bug or something about app lab or javascript I just don’t know?

Terry Henderson
(Professional Software Developer for 10 years before I became a teacher)


#2

In most circumstances you can safely ignore the yellow triangle warnings (which I know is frustrating for students sometimes) regardless of what the error is about.

It is a javascript issue more than applab. Javascript enforces strict(er) type checking with the triple-equals, and tries to coerce the type with double-equals. We teach the == because in many cases for students they want the more permissive version of equality checking because they might be comparing a number in a textbox (text) with a number (integer) or vice versa. This is true for primitive types.

for example:

> “4”==4
true
> “4”===4
false

You might see this in applab code when you do a getValue from a field, as in:

if( getValue("myScore") == 10 ){
     setValue("result","You win!");
}

But javascript complains when you mix types using double-equals because it’s worried you don’t know what you’re doing :slight_smile:

Baker
CSP Team