0
intricate
If the Boolean value is assigned to an integer, then the truth becomes 1, and the false becomes 0. If an integer value is assigned to a Boolean, then 0 becomes false (false) and any value not equal to zero becomes true. please show these variations with an example
1 Answer
+ 1
+ sign: convert boolean (or any other data type) to integer (equals to Number())
!!: converts any data type to boolean (equals to Boolean())
a = true;
b = false;
alert(+a) //1
alert(+b) //0
alert(+a + +b) //1 + 0 = 1
x = 5;
y = 0;
alert(!!x) //true
alert(!!y) //false
alert(+!!x) //1
alert(+!!y) //0