For unequal types, "==" operator would first coerce the values to Number types
Inputs :
A =10, is number type, B =true, is boolean type
Code: Which block will run?
if(A == true) { console.log("if block") } else { console.log("else block") }
Reasoning :
"==" would do this coercion A === ToNumber(B)
ToNumber(B) ie ToNumber(true) results in 1
10 === 1 ? Answer is : "else block" will be printed on console
developer.mozilla.org/en-US/docs/W...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
For unequal types, "==" operator would first coerce the values to Number types
Inputs :
A =10, is number type,
B =true, is boolean type
Code: Which block will run?
if(A == true) {
console.log("if block")
} else {
console.log("else block")
}
Reasoning :
For unequal types, "==" operator would first coerce the values to Number types
"==" would do this coercion A === ToNumber(B)
ToNumber(B) ie ToNumber(true) results in 1
10 === 1 ?
Answer is : "else block" will be printed on console
developer.mozilla.org/en-US/docs/W...