Comparison with the inequality operator(!=)

Tell us what’s happening:
Describe your issue in detail here.

1 !=  2
1 != "1"
1 != '1'
1 != true
0 != false

In order, these expressions would evaluate to true , false , false , false , and false .

My issue is mentioned that thing in description , my according
1 != 2 → true
1 != “1” ->true(because “1” is string)
1 != ‘1’ ->true(coz ‘1’ is string)
1 != true ->true
0 != false → true

but in the description there is something else. Kindly clear my confusion.

   **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: Comparison with the Inequality Operator

Link to the challenge:

!= is a weak comparison where the left and right side will be cast to the same type.
You probably want strong comparison !==.

1 Like

it can convert datatype while comparing isn’t it confusing then what is the point of comparison then? below lines are from description
" Like the equality operator, the inequality operator will convert data types of values while comparing."

1 Like

I have no idea why the people who wrote JavaScript made a weak comparison operator ==. I never use it, personally.

2 Likes

I blame Microsoft jScript, circa 1996, when we didn’t know better. And now, with legacy code, we’re stuck with it.

There are a number of wonky things in javascript, often introduced in the early days before there was a standard. And many of them were quick to be adopted and used in production. At that point, we’re stuck with them. Mozilla will often list syntax parts as obsolete or discouraged, but they can’t really be removed.

1 Like

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