Sorry for the question, I wasn't sure how to ask it. Basically I'm practicing JavaScript using logic operators. I have a really simple HTML code:
<body> <script src="logic_operators.js"></script> </body>
The file "logic_operators.js" has the next lines of code:
let value1 = true;
let value2 = false;
document.write(value1 && value2 + '<br/>');
document.write(value1 || value2 + '<br/>');
document.write(!value1 + '<br/>');
document.write(!value2 + '<br/>');
Basically, each document.write()
sentence writes the result of each logic operant with a new line.
It works for each sentence except for the OR ( || ) one, it doesn't print the new line. I get the next result:
false
truefalse
true
I need to enclose the OR operation using parenthesis for the sentence to work:
document.write((value1 || value2) + '<br/>');
Why is that? I'm new to JavaScript and can't really figure this out.
)` – Kinglish Jun 11 '21 at 23:10