+ 10
Why output is 1111
Why 1111 https://code.sololearn.com/WCBWbDb6n8w2/?ref=app There is a++ and b++
16 Respostas
+ 16
~ swim ~
Since JavaScript is loosely typed, it coerces values into booleans in logical expressions. 'if' statements, '&&', '||', and ternary conditions all coerce values into booleans.
NOTE: that this doesnât mean that they always return a boolean from the operation.
There are only six "falsy" values in JavaScript â 'false', 'null', 'undefined', 'NaN', '0', and '""' â and "everything else is truthy".
This means that '[]' and '{}' are both truthy, which tend to trip people up.
https://code.sololearn.com/WGcUsD16NTtN/?ref=app
+ 16
~ swim ~ Don't worry friend,
Everything is fine!đ
We try to explain, doing the best as we can!đ
+ 15
The OR || operator does the following:
âą Evaluates operands from left to right.
âą For each operand, converts it to boolean. If the result is 'true', stops and returns the original value of that operand.
âą If all operands have been evaluated (i.e. all were 'false'), returns the last operand.
A value is returned in its original form, without the conversion.
In other words, a chain of OR "||" returns the first truthy value or the last one if no truthy value is found.
+ 15
~ swim ~ Yes,
but where's misleading!?
+ 10
~ swim ~ Speaking for myself and many others I know who feel the same way... the quality and accuracy of the knowledge you share is consistently impeccable and a treasured asset in this community.
On the rare occasion where you might have posted a comment that doesn't completely make sense, I almost always realize you're speaking from a different frame of context.
At the very least, I will always give you the benefit of the doubt due to your high credibility established over the time you've been active here.
As it is with the many talented and selfless contributors here, you aren't given the praise and recognition you deserve. And, like many, such praise and recognition doesn't seem to be your motivation.
Regardless... from one community member to another, I just want to genuinely express my gratitude and appreciation for all your invaluable contributions and the countless people you've come to help in this amazing community.
Here's to you mate! đ»đđ€đ
+ 8
~ swim ~ Your explanation applies to statically typed languages like C, C++, Java, C#, etc.
However, in Javascript, logical operators return true or false only when the operand is a boolean value.
Or more accurately stated, the result will reflect the value of the operand that satisfies the logical operation. (This essentially summarizes the points made earlier by Danijel IvanoviÄ.)
The link below provides a more thorough explanation to better understand how Javascript handles truthy and falsy expressions.
https://mariusschulz.com/blog/the-and-and-or-operators-in-javascript
You can skip to the section titled "Using Logical Operators with Non-Boolean Values" for this specific topic:
https://mariusschulz.com/blog/the-and-and-or-operators-in-javascript#using-logical-operators-with-non-boolean-values
I also recommend reviewing the section on "Coercion to Boolean Values" to explicitly force logical operations with non boolean values to produce boolean return values.
+ 4
Why the second statement is not evaluated? Both statements should be checked...
+ 2
you used the increament method a++ which means the a variable is 11 after the if statement
the statement a++ >= 11 || b++ >= 11 is true but the ! will reverse it, which means that the if block wont excute then the else code will run.
0
it is only js