That means there is no number greater than the infinity when compared with infinity. The initial value of Infinity is Number.POSITIVE_INFINITY.
It’s syntax looks like –
For more detail about JavaScrip Infinity click here.
First, we declare a variable number with let keyword and assign Infinity value to number variable.
let number = Infinity;
In the second step, we are comparing a variable number with the boolean value true to check whether it returns true or false. A
console.log(number == true); // output => ?
Now in the next step, we use a not operator with number variable and print the output using console log.
Any guess what is the output of above two statements ?
Now, you know the answer is “false, false“. But why it giving false for both cases if first case giving false then last should give true.
So, for the first console log statement, it gives false because it’s clearly seen that number which has an Infinity value not equal to true.
Now, in the next step when we use console log with number with ! not operator.
So, not operators convert the value to boolean as Infinity is a truthy value so when not-operator used with it converted to a false value.
At last, That’s why we get an answer “false, 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 –
- JS Quiz – can string split method will be limited
- JS Quiz – can array from method be like a map method
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.