Why is true * true === 1 in JS?

After going through the good parts and messing around in node, I wonder why this is happening. I know it! refers to the operator "logical not", and that is !! basically booleanates (ifies?) return value! x, but why is it?

var x = 3, y = 4;

x != y;     // true
x = !y      // false ----> But really, its setting x to "not y", a truthy value, correct
x = !!x*x   // 1 --- wut?

So, after playing a little with this, I understand that the declared: "x is not x (" true ", because! X === false) times x (true)"

So, I think, the question is why true * true === 1 in JS?

+4
source share
2 answers

The operator *would force trueto 1for the purpose of computing the multiplication of and 1 * 1 === 1.

+4
source

false 0, True 1. , , 1 * 1 = 1? , .

+1

All Articles