Why is {} + 'equals 0?

as shown in figure

clipboard.png

preliminary doubt whether the empty string on the right is converted to 0?

Mar.04,2021
The

operator +, when used as a unary operator, converts it to a numeric value if its Operand is not a numeric value.
you may wonder why there is an empty object ({}) in front of + here why it interprets + as a unary operator? Because in this case, the preceding {} is not an empty object, but an empty code block (empty code block).


this is the default conversion of the data type of js. Your suspicion is correct, but it is converted by pulling several js methods in the middle

.
Menu