Comparison Operators

let hungerLevel = 7;
if(hungerLevel > 7){
console.log(‘Time to eat!’)
console.log(‘We can eat later!’)

Hi, I am a bit confused about the difference between ‘=’ and ‘<=’. when I saw the explanation that shows it is greater or equal, I practiced using it, the result was just equal which was true, and ‘Time to eat!’. Wondered when I need to use ‘<= ’ or ’ =>’ since the result becomes equal. Thank you in advance.

= is the assignment operator:

const a = 42;

An assignment is always right to left. The value on the right is assigned to the variable on the left.

Inequality operators:

<    less than (or comes before)
>    greater than (or follows after)
!==  not identical to (strict type match and value)
!=   no apparent similarity (uses coercion)

as well as partial inequality:

<=   less than or equal to
>=   greater than or equal to

equality operator (uses coercion)

==   equality where one value looks like another

identity operator (strict type matching)

===  identical in value and type
1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.