console.log([] + {});
Output:"[object Object]"[]becomes""(empty string) when coerced to string.{}becomes"[object Object]"."" + "[object Object]"→"[object Object]".
console.log({} + {});
Output:"[object Object][object Object]"{}is treated as a block in JS if it’s the first statement.- The second
{}is coerced to"[object Object]". - Using
+with objects converts them to strings →"[object Object][object Object]".
console.log(+true);
Output:1- Unary
+convertstrue→1.
- Unary
console.log("10" - "5");
Output:5-operator converts strings to numbers →10 - 5 = 5.
console.log("10" + "5");
Output:"105"+with strings → string concatenation →"10" + "5" = "105".
console.log(undefined + 1);
Output:NaNundefinedconverted to number →NaN + 1 = NaN.
console.log(NaN === NaN);
Output:false- In JS,
NaNis not equal to itself.
- In JS,
console.log(typeof null);
Output:"object"- Legacy JS behavior;
nullis a primitive buttypeof nullreturns"object".
- Legacy JS behavior;
console.log(!!"");
Output:false- Empty string
""is falsy.!!converts it to boolean →false.
- Empty string
console.log(!!" ");
Output:true- String with a space
" "is truthy.!!" "→true.
- String with a space
💡 Summary
+operator can coerce types.-always converts to number.""is falsy," "is truthy.NaNis unique: not equal to itself.typeof nullis"object"due to JS legacy behavior.