Nęste
Forrige
Oversigt
JavaScript "Core Language" serie, Planche nr. 15
Kursus Indhold

Sammenligninger

Comparison Operators
Operator Description Examples returning true1

Equal (==)

Returns true if the operands are equal. If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison.

3 == var1
"3" == var1
3 == '3'

Not equal (!=)

Returns true if the operands are not equal. If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison.

var1 != 4
var2 != "3"

Strict equal (===)

Returns true if the operands are equal and of the same type.

3 === var1

Strict not equal (!==)

Returns true if the operands are not equal and/or not of the same type.

var1
!== "3"
3 !== '3'

Greater than (>)

Returns true if the left operand is greater than the right operand.

var2 > var1

Greater than or equal (>=)

Returns true if the left operand is greater than or equal to the right operand.

var2 >= var1
var1 >= 3

Less than (<)

Returns true if the left operand is less than the right operand.

var1 < var2

Less than or equal (<=)

Returns true if the left operand is less than or equal to the right operand.

var1 <= var2
var2 <= 5


© 1999 BLA*net - Leif E. Andersen, leander@blanet.dk