Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "!==" and "==!" [closed]

People also ask

What is the difference between !== And !=?

!= will only check value regardless of operands type. but !== is used to compare both value & type of 2 operands that are being compared to each other.

Why do we prefer === and !== Over == and != In Javascript?

The difference between == and === is that: == converts the variable values to the same type before performing comparison. This is called type coercion. === does not do any type conversion (coercion) and returns true only if both values and types are identical for the two variables being compared.

What is !== In PHP?

” and “==!” in PHP. !== Operator: It is called as non-identical operator. It returns true if operands are not equal, or they are not of the same type.

What is != And !== In Javascript?

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


The difference is that there is no operator ==!.

This expression:

$a ==! $b

Is basically the same as this:

$a == (!$b)

There is no ==! operator in PHP

Its just a combination of == and !. Only relevant operator present here is ==. So the combination ==! will work just as a normal ==, checking Equality, and trust me,

$variable_a ==! $variable_b 

is none other than

$variable_a == (!$variable_b)

and thus;

"a" ==! " ": bool(false)
"a" ==! "a": bool(false) //is same as "a" == (!"a")

And

true ==! false: bool(true)
true ==! true: bool(false)

Combining multiple operators characters may not work as an operator always. for example, if we take = and !, it will work as operators only if it is in the pattern of != or !==. There can be numerous combinations for these characters like !====, !==! etc.. etc.. Operator combinations should be in unique format, unique order, unique combinations (all characters wont combine with all other characters) and definitely, without any space between them.

Check the operators list below;

enter image description here


==! is not an operator but two :

== and !

! having a higher priority than ==

So :

"a" !== " ": bool(true) --> true because "a" is really not equal to " "

"a" ==! " ": bool(false) --> false because "a" is not equals to !" "

Could be written with a space between == and !.


==! doesn't exist as such. It's a somewhat cryptic notation of == !

As spaces don't matter in those operations, you could just as easily write a --> b, which evaluates to a-- > b, but will look strange.

So, as to the question: "a" ==! " " will be parsed to "a" == !" ". Negation of a string is covered by casting, meaning any string but "0" and " " is, when casted, true.

Thus, the expression "a" == !" " will get transferred:

  1. "a" == !" "
  2. "a" == !false
  3. "a" == true

And, as string "a" is not the same as bool true, this evaluates the whole expression to false.

So, what's the moral of the story? Don't let yourself be confused by missing or wrong placed spaces! :)


==! is not an operator

==! isn't a php comparison operator at all - it is the same as == ! (note the space)

I.e.

if ("a" !== " ") {
    // evaluates to true - "a" and " " are not equal
}

if ("a" == !" ") {
    // unreachable
} else {
    // evaluates to false - "a" is not equal to true (!" " evaluates to true)
}