Questions tagged [not-operator]

A unary Boolean operator that negates its operand. !TRUE = FALSE.

A unary (has only one operand) Boolean operator that negates (performs a NOT operation on) its operand. In most programming languages it is either ! (C, C++, Java, Javascript, PHP, etc.) or NOT (Basic, Pascal, Ada, etc.).

  • !TRUE = FALSE
  • !FALSE = TRUE

Negation on Wikipedia

52 questions
381
votes
10 answers

What does "!--" do in JavaScript?

I have this piece of code (taken from this question): var walk = function(dir, done) { var results = []; fs.readdir(dir, function(err, list) { if (err) return done(err); var pending = list.length; if…
Kieran E
  • 3,616
  • 2
  • 18
  • 41
59
votes
19 answers

Which is clearer form: if(!value) or if(flag == value)?

I understand this is a subjective question, so I apologize if it needs to be closed, but I feel like it comes up often enough for me to wonder if there is a general preference for one form over the other. Obviously, the best answer is "refactor the…
CodexArcanum
  • 3,944
  • 3
  • 35
  • 40
48
votes
41 answers

Should I use `!IsGood` or `IsGood == false`?

I keep seeing code that does checks like this if (IsGood == false) { DoSomething(); } or this if (IsGood == true) { DoSomething(); } I hate this syntax, and always use the following syntax. if (IsGood) { DoSomething(); } or if…
chills42
  • 14,201
  • 3
  • 42
  • 77
27
votes
4 answers

What does an exclamation mark in array index do?

While perusing through my organization's source repository I came across this little gem: RawParameterStorage[!ParameterWorkingIdx][ParameterDataOffset] = ... Is this valid code? (It compiles) What does the exclamation mark here do? An invert ~…
Jim Fell
  • 13,750
  • 36
  • 127
  • 202
11
votes
4 answers

Python not equal operator

I come from a c style languages, so I am natural in using != as not equal, but when I came to Python, from the documentation I read, I learned that for this purpose the <> operator is used. Recently, I have seen a lot of code using !=, so my…
coredump
  • 3,017
  • 6
  • 35
  • 53
10
votes
4 answers

Why does this bitwise shift-right appear not to work?

Could someone explain to me why the mask is not shifted to the right at all? You can use anything in place of that 1 and the result will be the same. unsigned mask = ~0 >> 1; printf("%u\n", mask);
Ree
  • 6,061
  • 11
  • 48
  • 50
5
votes
3 answers

MySQL - NOT IN LIKE

How can I, in mysql, check if a value is inside a number of fields in another table? Something like SELECT * FROM table WHERE concat('%',value,'%') NOT LIKE IN(SELECT field FROM anothertable) But I don't think that's quite right, is it?
James T
  • 3,292
  • 8
  • 40
  • 70
5
votes
12 answers

What does if (!$variablename) do in PHP?

I know that != is "not equal", but what does it mean when you have this: if(!$something) My first guess is something to do with exceptions, but a look around google did not return anything. So what does this do?
1321941
  • 2,139
  • 5
  • 26
  • 49
5
votes
2 answers

Double not (!!) vs type coercion in JavaScript

Is there any advantage, except indicating an explicit conversion, to using a double not operator in JavaScript? It often seems that these days, people like to check for existence of new APIs using the double not, but I have never, ever read any…
Joshua W
  • 1,103
  • 12
  • 29
4
votes
1 answer

Overloading logical NOT operator vs bool type-cast operator

Consider the following code: class Truth { public: Truth(bool val) : value(val) {} bool operator!() {std::cout<<"operator!()"<
imreal
  • 10,178
  • 2
  • 32
  • 48
4
votes
1 answer

NOT operator doesn't work in query lucene

I use lucene version 3.0.3.0, but some expression that i search, doesn't work properly. for example if i search "!Fiesta OR Astra" on field "Model", "vauxhallAstra" is returned only and "fordFocus" is not returned. my code is below: var fordFiesta =…
Iman 1989
  • 43
  • 1
  • 3
3
votes
3 answers

Not operator in regular expression

Given the following string 1080s: 33, 6'2" meg: test. 1748s: I THINK IM GONNA PICK 1749s: TWO COMPLETE OPPOSITES. I want to do regex operation on it, and want the following matches 1st match : 1080s: 33,…
meghana
  • 907
  • 1
  • 20
  • 45
3
votes
4 answers

Can the NOT operator work on multiple conditions present in parenthesis?

I run following query in MySQL : SELECT * FROM Customers WHERE NOT Country='Germany' AND NOT Country='USA'; It returned me exactly the correct expected result. After that I run following query : SELECT * FROM Customers WHERE NOT (Country='Germany'…
PHPLover
  • 1
  • 51
  • 158
  • 311
3
votes
1 answer

Does operator precedence explain the difference in these expressions involving multiplication of a numeric with a negated logical?

I have three expressions, each involving multiplication with a logical or its negation. These logicals and their negation represent indicator variables, so that the expressions are conditionally evaluated: -2*3*!T + 5*7*T 5*7*T + -2*3*!T (-2*3*!T)…
Alex
  • 15,186
  • 15
  • 73
  • 127
3
votes
3 answers

Not operator, seemingly wrong in Python?

I am new to python and created a small function that does a cluster analysis. The quick rundown is I have to compare two arrays a multitude of times, until it no longer changes. For that I have used a while loop, that loops as long as they are not…
Rewned
  • 61
  • 4
1
2 3 4