0
What is the difference between bitwise operator and logical operator in javascript
I used to be confused on the two because I dont really get the difference between them especially the use of bitwise operator in javascript, I need more a more advanced explanation on it please!!, and how they are used
1 Answer
0
bitwise operators works with each bit in numbers
logical OR operation of each bit in compared numbers: 5 OR 3 return 7 because
5 = 0101 binary
3 = 0011 binary
0111 binary result, 7 as decimal representation
so
0b101 | 0b011 = 7
5 | 3 = 7
logical operation works in correct way with boolean true false values
true || false = true
but in JS is possible to use
non "empty" value as true
and "empty" value like zero or null as false
so
5 || 3 = 5
means
true || true = true
(note, = in this post means "returns")