- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
If we look closely at the problem statement, the difference between ( == false) and ( || true) is the following −
In the first case, we are using loose conditional checking, allowing type coercion to take over.
While in the second case, we are evaluating  to its respective Boolean (truthy or falsy) which makes use of the function Boolean() instead of type coercion under the hook.
Let's now unveil the conversions that happens behind the scenes in both cases.
Case 1 − ( == false)
According to the MDN docs if two data types say x and y are compared using the loose equality operation ( == ), then,
The boolean value will be converted to a Number using the Number() function −
So, the condition now becomes −
 == 0// Number(false) = 0
Then if the variable of Object type will be converted to primitive value −
"" == 0
And lastly the empty string will be converted to a Number −
0 == 0
The above eventually returns true
Case 2 − ( || true)
In this case the truthy/falsy value of  will be checked by converting it to a boolean using the inbuilt Boolean() function. And,
Boolean() = true
Hence, the truthy value  is retained.
- Why does MySQL evaluate “TRUE or TRUE and FALSE” to true?
- Are true and false keywords in java?
- True, False and Nil in Ruby Programming
- Why does php's in_array return true if passed a 0?
- Geolocation HTML5 enableHighAccuracy True, False or What?
- Display TRUE FALSE records as 0 1 in MySQL
- What are False Positives and True Positives in Cybersecurity?
- Return true or false in a MySQL select if another field contains a string?
- Why mean is NaN even if na.rm is set to TRUE using dplyr in R?
- How to plot true/false or active/deactive data in Matplotlib?
- Is the concept of resveratrol true? How does it help?
- How can I count true and false values in my PHP array?