Jump to content

Boolean values: Difference between revisions

m
→‎{{header|Phix}}: subtly reduced the implication of either defending Phix or accusing JavaScript (or vice versa).
m (C# Removed the remark about C#8 nullable types because it does not apply to bool.)
m (→‎{{header|Phix}}: subtly reduced the implication of either defending Phix or accusing JavaScript (or vice versa).)
Line 1,975:
The builtin constants TRUE/FALSE and their aliases True/true/False/false may also be used.
 
There is however a gotcha in JavaScript, and hence pwa/p2js, in that <b>true !== 1</b> and <b>false !== 0</b>. In almost all other respects, true is 1 and false is 0, for instance 1+true evaluates to 2, just like desktop/Phix. It is only direct comparison for equality of booleans and numbers using an infix operator which fails, and I suppose you could argue that is a programming logic blunder, (by which I mean in a particular source file of a specific application, rather than in the (Phix ''or'' JavaScript) programming language definition). There is no such issue with equal() and compare(), which of course can be used instead, and pwa/p2js automatically maps to when needed, that is except for bool vs number, which is difficult because in desktop/Phix those <i>those are the same thing</i>. Thankfully, there are very few places anyone ever actually compares bools against 0 and 1 using an infix operator.
 
The following example illustrates, and also emphasies the subtlety of the issue (no difference whatsoever if c, d, e, f are defined as bool):
7,813

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.