JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – does false compare with false return false

JavaScript Quiz – does false compare with false return false

False compare with false

False is a javascript boolean value and boolean have only two value true & false but when compare boolean value compare with boolean value then based on their value it return boolean.

If both boolean value is same then it true but if different then return false.

Look at basic example of Boolean Value

true
false

For more detail about the javascript boolean value click here.

JavaScript Question

In this javascript quiz, find out does false compare with false returns false because both of them is a boolean value then it should be true.

First we declare an variable x using let keyword and assign a false value to it.

let x = false;

Now create an another variable y and assign boolean value using new Boolean().

let y = new Boolean(false);

Finally we compare this two value and also with typed equal.

console.log(x == y); 
console.log(x === y); 

Any idea what should be the output of above code statement.

JavaScript Quiz Test

Here is the full javascript code snippet for you to solve.

let x = false;             
let y = new Boolean(false);

console.log(x == y);  // output => 🧐 ?
console.log(x === y); // output => 🧐 ?

// Made with ❤️, by @jsstartup

Answer – true, false

Click To Run Code

Explanation

Now you know the answer is true, false. But why doesn’t both of them should give the same output because both are false. Let me explain.

So, it true both value is false that’s why it return a true.

But if you can see that y is a boolean object created using new Boolean(). Whose data type is an object. But x value is false whose data type is Boolean.

At last, That’s why we get an answer “true, false“.

Let me know in the comment section, what you think about it.

I hope you understand the concept and logic behind it.

But wait, i have something more for you –

Check out our other javascript quiz – 

  1. JavaScript Quiz – can mixed case array sort is possible
  2. JS Quiz – effect of misplaced semicolon after if statement
  3. JS Quiz – what does triple value compare 10 > 9 > 8 return
  4. JavaScript Quiz – does it shift array element to the right

Conclusion

To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
0 Shares
Share via
Copy link