0 votes
in JavaScript by
If the following lines of code differ, what is the difference?

Code A

!!(obj1 && obj2);  

Code B

(obj1 && obj2);  

a) The first line results in a realBoolean value whereas the second line merely checks for the existence of the objects

b) Both the lines of code A and B will result in a Boolean value "False"

c) Both the lines of code A and B will check just for the existence of the object alone

d) Both the lines of code A and B will result in a Boolean value "True"

1 Answer

0 votes
by

Answer: A

Reason: Code A will return output in the form of a "real" boolean value because we first do what is written inside the parentheses, but then negate it again immediately. Therefore, it is saying something that is not true, makes it true.

Code B looks for the existence of the obj1 and obj2. Also, it may not necessarily return a "real" boolean value. This means instead of returning either true or false and it can be problematic because false-y can be either an empty string or can be 0.

Related questions

0 votes
asked Mar 23, 2021 in JavaScript by sharadyadav1986
0 votes
asked Nov 14, 2020 in JAVA by rajeshsharma
...