Voltra Neo Voltra Neo - 1 year ago 116
Javascript Question

JSLint error from ternary statement

I'd like to know why ternary conditional-statements like these:

on_actu.boolean ? IMG1 = "on-actu.png" : IMG1 = "off-actu.png";

give me the following JSLint error :

expected an assignment or function call and instead saw an expression

Answer Source

You're using the ternary operator wrong.

ValueToAssign = BooleanConditional ? valueOne : valueTwo;

More information here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download