0

I am new to java-script and not able to understand the use of | operator in following code snippet

<!DOCTYPE html> <html> <body> <p>Click the button to display a number between 0 and 1</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var a=Math.random(); var x = ((a*2 | 0)); document.getElementById("demo").innerHTML = x; } </script> </body> </html>

3

1 Answer 1

1

That's bitwise OR operator

Performs the OR operation on each pair of bits. a OR b yields 1 if either a or b is 1. The truth table for the OR operation is:

Bitwise ORing any number x with 0 yields x. Bitwise ORing any number x with -1 yields -1.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.