boolean return value true with string
We will use above this two method to manipulate the boolean value data type.
Basic Syntax of Boolean Method
For more detail about the Boolean and there method click here.
First, we declare a variable boolean and assign a comparison value to it. Which return a boolean value.
let boolean = 10 > 9;
Now, we check the value of boolean variable and use toString() method with it.
Again, we check the same variable with valueOf() method.
Any idea, what should be the output of above code statement.
Here is the full code snipper for you to solve.
let boolean = 10 > 9; console.log(boolean.valueOf()); // output => 🧐 ? console.log(boolean.toString()); // output => 🧐 ? // Made with ❤️, by @jsstartup
Now, you know the answer is true, “true”. But why they look same than what’s the difference. Let me explain.
So, in short toString() method return a string value which mean it convert the boolean value to string.
And for valueOf() method, it return the primitive value which is actual value true.
At last, That’s why we get an answer true, “true“.
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 – does get date and month from date object is same
- JS Quiz – does the string startsWith() method return true
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.