# 小伙伴的提问{}+1是咋回事

* 抖音：<https://v.douyin.com/iUB6mVab/>
* B站：<https://www.bilibili.com/video/BV1iw4m1e7vk/>

这个问题好玩哈

他说正常如果我们用 1 + {}

结果肯定是 1Object

其实就相当于做了一个字符串拼接

把这个大括号当成了空的object

但是呢按照这个逻辑

大家看我们反过来用大块加一

结果就变成"1"了

真的很奇怪啊

而且呢

他发现如果我们用小括号把它扩上

他又可以了

其实原因很简单啊

就是在这种情况下

js的解析器

会把这个大括号当成一个空的代码段

我这样写就明白啊

就随便写点： a = 'xiaoshan'

然后呢大家看

就像是这样

所以呢像刚才这样写呢

就相当于我们写了一个 "+1"

结果就是

那为什么用小括号扩上就可以呢

因为小括号扩上

他就不会把里面大括号

当成一个空的代码段了

他其实就是一个空的object了

甚至呢我们把它这样扩上

他也会把它整体当成一个二元运算

那为什么反过来 1 + {} 可以呢

其实也是一样的

因为这种情况

如果再把大括号当成一个空的代码段

那么"1 +"就不是一个完整的表达式了

所以

他会默认把这个大括号当成一个object


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sunzsh.gitbook.io/xiaoshan.bug/xiao-huo-ban-de-ti-wen-+1-shi-za-hui-shi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
