+ 3

I need help with this statement: console.log(!!"false" == !!"true")

I want to know execution process in depth

16th Jul 2021, 7:30 AM
Lohith Viswa
Lohith Viswa - avatar
3 Answers
+ 5
> !!"" false > !!"any string" true > !!"true"===!!"false" true
16th Jul 2021, 7:57 AM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 4
I think it works something like this: In your code, "false" and "true" are two strings not boolean values. !"false" becomes false because it means, it is not a string so it becomes false in boolean value. !"True" becomes false in boolean value for the same reason. so it means you are comparing (!false==!false) inside console.log(). here !false =true so now it can also be said like that, true==true which is true. So the summary is: console.log(!!"false" == !!"true") is the same as: console.log(!false==!false) is the same as: console.log(true==true) is the same as: console.log(true)
16th Jul 2021, 7:53 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 3
"false" and "true" by themselves are just strings, but when you add the negation operator !, they will be viewed as truthy or falsy objects. Any non-empty strings in Javascript are viewed as truthy and an empty string is falsy. So, both will evaluate 1st to true and then be negated ! to false then back again to true. Then they are compared to each other == and true is finally returned and output. !!"false"==!!"true" !! true==!!true !false==!false true==true true
16th Jul 2021, 7:53 AM
ChaoticDawg
ChaoticDawg - avatar