Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to use NOT or <> when comparing values?

Tags:

vbscript

Is it better to use NOT or to use <> when comparing values in VBScript?
is this:

 If NOT value1 = value2 Then 

or this:

 If value1 <> value2 Then 

better?

EDIT: Here is my counterargument.
When looking to logically negate a Boolean value you would use the NOT operator, so this is correct:

  If NOT boolValue1 Then 

and when a comparison is made in the case of the first example a Boolean value is returned. either the values are equal True, or they are not False. So using the NOT operator would be appropriate, because you are logically negating a Boolean value.

For readability placing the comparison in parenthesis would probably help.

like image 751
Tester101 Avatar asked Dec 15 '08 20:12

Tester101


People also ask

Should I use != Or !==?

Inequality Operators: !=!= : Converts values if variables are different types before checking for inequality. !== : Checks both type and value for the two variables being compared.

Is a comparison operator or not?

Comparison operators can compare numbers or strings and perform evaluations. Expressions that use comparison operators do not return a number value as do arithmetic expressions. Comparison expressions return either 1 , which represents true, or 0 , which represents false.

What's 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.


1 Answers

The latter (<>), because the meaning of the former isn't clear unless you have a perfect understanding of the order of operations as it applies to the Not and = operators: a subtlety which is easy to miss.

like image 60
Joel Coehoorn Avatar answered Sep 23 '22 02:09

Joel Coehoorn