Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dual or triple (or even multiple) comparison in JavaScript

Tags:

javascript

Almighty Gurus, Please tell me, I want to know can comparison sm. set of variables in row, like this:

x < y >= z 

or i need to do it in two steps?

(x < y) && (y >= z)
like image 305
Maxja Avatar asked May 17 '10 09:05

Maxja


People also ask

Should I use == or === in JavaScript?

== in JavaScript is used for comparing two variables, but it ignores the datatype of variable. === is used for comparing two variables, but this operator also checks datatype and compares two values. Checks the equality of two operands without considering their type.

What is === in JavaScript?

The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.

Why === is false in JavaScript?

Because == (and === ) test to see if two objects are the same object and not if they are identical objects.

What is triple equals in JavaScript?

The triple equals operator ( === ) returns true if both operands are of the same type and contain the same value. If comparing different types for equality, the result is false. This definition of equality is enough for most use cases.


2 Answers

In Javascript, you must do this type of comparison in two steps.

Python is the only widely used language I'm aware of that allows the first form (please comment if I'm incorrect).

like image 54
Greg Hewgill Avatar answered Oct 24 '22 21:10

Greg Hewgill


You can only do the latter in Javascript:

(x < y) && (y >= z)
like image 29
Sarfraz Avatar answered Oct 24 '22 20:10

Sarfraz