JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – what does triple value compare 10 > 9 > 8 return

JavaScript Quiz – what does triple value compare 10 > 9 > 8 return

In this javascript quiz, you need to find out what does the triple value compare 10 > 9 > 8 return because we mostly compare two values of the same data type.

In javascript, greater than > is a logical operator which check for greater value among two.

JavaScript Question

First, we declare a variable boolean and assign triple value compares in it.

let boolean = 10 > 9 > 8;

Now, the value store in boolean put in if statement and return true & false based on boolean value.

if(boolean){
  console.log(true);
} else {
  console.log(false);
}

We use a console log to print the output value. So, any idea what should be the output of the above code statements.

JavaScript Quiz Test

Here is the full code snippet for you to solve.

let boolean = 10 > 9 > 8;

if(boolean){
  console.log(true);
} else {
  console.log(false);
}
// output => 🧐 ?

// Made with ❤️, by @jsstartup

Answer – false

Click To Run Code

Explanation

Now, you know the answer is “false“. But why doesn’t it should give the true. Let explain.

To solve this, we need to break the condition in two step. First we compare the 10 > 9 and then it’s output compare with 8.

((10 > 9) > 8)

Now, we compare all condition step by step.

Note: true converted to 1 in number when compare.

((10 > 9) > 8)
(true > 8)
(1 > 8)
false

Now, if check the condition in if statement.

if(false){
  console.log(true);
} else {
  console.log(false);
}
// output => false

At last, That’s why we get an answer 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. JS Quiz – does the string startsWith() method return true
  2. JavaScript Quiz – boolean return value true with string or not
  3. JavaScript Quiz – can mixed case array sort is possible
  4. JS Quiz – effect of misplaced semicolon after if statement

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