Home » JavaScript » JavaScript Functions » Question
  1. What is the difference between the two lines given below ?
    !!(object1 && object2);
    (object1 && object2);
    1. Both the lines checks just for the existence of the object alone
    2. The first line results in a real boolean value whereas the second line merely checks for the existence of the objects
    3. Both the lines result in a boolean value “False”
    4. Both the lines result in a boolean value “True”
    5. None of these
Correct Option: B

The first returns a “real” boolean value, because you first negate what is inside the parenthesis, but then immediately negate it again. So, it’s like saying something is “not not” truth-y, making it true. The second example simply checks for the existence of the object1 and object2, but might not necessarily return a “real” boolean value, instead returning something that is either truth-y or false-y. This can be problematic, because false-y can be the number 0, or an empty string, etc. Simple existence can be truth-y. A “real” boolean will only be true or false.



Your comments will be displayed only after manual approval.