Try this, open the console:
{} + 1
> 1
And
({}) + 1
> "[object Object]1"`
So what the duck is going on there? What are the extra brackets adding?
Try this, open the console:
{} + 1
> 1
And
({}) + 1
> "[object Object]1"`
So what the duck is going on there? What are the extra brackets adding?
{} + 1
Is being read as "empty code block" + 1
({}) + 1
Is "object" + 1
Take a look at the difference between just {}
and ({})
, for instance. As far as what a code block is:
{
// any code here is valid, this is an anonymous block
}
When does {
define a code block vs an object? If you're similar with the rules of function statements vs function expressions, I believe they're exactly the same in this case:
{
is at the beginning of a line, it's a code block