+ 10

Why output is 1111

Why 1111 https://code.sololearn.com/WCBWbDb6n8w2/?ref=app There is a++ and b++

8th May 2019, 4:57 PM
Sławek J.
9 ответов
+ 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
8th May 2019, 8:56 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 16
~ swim ~ Don't worry friend, Everything is fine!👍 We try to explain, doing the best as we can!😊
8th May 2019, 9:24 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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.
8th May 2019, 7:27 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 15
~ swim ~ Yes, but where's misleading!?
8th May 2019, 8:08 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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! 🍻🎊🤓👌
8th May 2019, 9:28 PM
David Carroll
David Carroll - avatar
+ 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.
8th May 2019, 8:47 PM
David Carroll
David Carroll - avatar
+ 4
Why the second statement is not evaluated? Both statements should be checked...
8th May 2019, 6:09 PM
Sławek J.
+ 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.
9th May 2019, 9:45 AM
khalil Saghiri
khalil Saghiri - avatar
0
it is only js
12th May 2019, 1:53 AM
Tigee
Tigee - avatar