Why is the output of the following code is 1
function test(){} + 1; // output: 1
Why is the output of the following code is 1
function test(){} + 1; // output: 1
Because of automatic semicolon insertion, that code is actually processed as:
function test(){}; + 1;
That's the unary plus operator, not the addition operator.
function test() or {} here is not an Object, its en empty statement and JS Cannot convert object to primitive value and find the safe route and convert this statement value to false.
{} + 1 = 1 because (false + 1) = always 1.