Content deleted Content added
→Boolean section: to 1 specifically→specifically to 1 |
m →Boolean section: -comma |
||
Line 292:
:As I said, I agree that some of the examples can be eliminated. I simply included the permutations because that's what you did... Needlessly, you more than quadrupled the original four examples: 1 and "0" for each.
:Contrary to what you keep repeating, you did '''''not''''' provide an example that clearly demonstrates the behavior of a Boolean operand being automatically converted to number for comparison. Frankly, the terms "truthy" and "falsy" were irrelevant except in so far as the behavior is somewhat counter-intuitive:
:In an equality comparison (non-strict, obviously) between a Boolean (on one side) and either a number or a string (on the other), the Boolean operand is converted to a number, rather than the non-Boolean operand being converted to a Boolean. Thus, a comparison between a Boolean and any number except 0, 1, (and NaN), or any non-empty string that can't be converted
:In addition to your 12 permutations of automatic v. strict comparison, you added a separate block: “Examples with "falsy" and "truthy" values”, making a peculiar example of the number 3, (rather than 2). In a line comment you say: “3 is logically true(known as "truthy"), as are all non-0 non-nan numbers. However, it is not "true", even with type coercion.” '''[''sic'']'''
:In a Boolean context, ''3 '''is''' always "true".'' Comparison is ''not'' a Boolean context. And comparison to a Boolean does ''not'' make it a Boolean context any more than comparison to a number makes it a numeric context, or comparison to a string makes it a string context. When 3 ''does'' get type converted ''(automatically or explicitly)'' to a Boolean, ''then'' it's always <code>true</code>, and never <code>false</code>, (whether or not that Boolean then gets discarded in favor of the original value, and so, arguably, wasn't so much "converted" as "interpreted"... just isn't the point.)
|