# Promise.resolve()使用场景（执行顺序续集）

{% embed url="<https://v.douyin.com/r6tRjn4/>" %}

{% embed url="<https://www.bilibili.com/video/BV11R4y1j7dk/>" %}

之前我一直想不通哈

这 Promise.resolve() 的应用场景

因为

他点then里面写的代码会直接被执行

大家看（直接弹出来了）

那跟我直接写alert(1)有啥区别呢

直到啊 这期视频发布以后

一个小伙伴在评论区里提出来

用它来进一步优化的一个方案

真的是太棒了哈

但遗憾的是

他那个评论我现在怎么翻也翻不到了

我给大家讲一讲哈

大概的意思是这样的

他在这个代码里边

提交的时候就不用做判断是否为空了

就直接用它点then

为什么呢

因为他在这不会给他置为空

会让他等一个 resolve

包括他初始值

也不是一个空

好我们再来试一下

我们再清一下啊，好 手机号我直接点提交

大家看：start

end、submit

如果直接点提交呢

就直接submit

这没有问题

那总结来说呢

这就相当于一个占位符一样

只不过呢他是立即执行的 Promise

它跟null的区别在于

它前后是类型是一致的

所以我们不需要再判断他是否为空了

当然了

这肯定是 resolve 的实用场景之一

肯定还有其他的应用场景

那还知道其他应用场景的小伙伴呢

我们评论区里见


---

# 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/promise.resolve-shi-yong-chang-jing-zhi-xing-shun-xu-xu-ji.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.
