A
A
ArtemEfremov2020-04-19 22:46:02
Node.js
ArtemEfremov, 2020-04-19 22:46:02

Not always working conditions or incorrectly written code?

Hello. Sometimes it happened. That when you put the condition "if, this is not what is given, then." For example:

var test = 1;
if(!test == 0) {
 console.log("Test не равен 0");
}


Sometimes it happened that NODE.JS completely ignored the '!' sign, wherever it appeared. And the condition didn't work.

The main question is: is this a flaw in the language or something else?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-04-19
@ArtemEfremov

test = 1
console.log(!test) // false

if (!test == 0)   // если "не тест", то есть false равен нулю или может быть приведен к нулю/false

if (test !== 0) // правильно
if ( !(test === 0) ) // работает правильно, выглядит некрасиво

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question