# 一个有趣的js语法糖 !!

**URL:** <https://www.shiqidu.com/t/topic/806>\
**Category:** 开发调优\
**Tags:** JavaScript\
**Created:** [2023 年11 月 8 日 12:31 UTC](https://www.shiqidu.com/t/topic/806 "2023-11-08T12:31:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![caojie](https://www.shiqidu.com/user_avatar/www.shiqidu.com/caojie/32/465_2.png) [@caojie](https://www.shiqidu.com/u/caojie)\
发布日期： [2023 年11 月 8 日 12:31 UTC](https://www.shiqidu.com/t/topic/806/1 "2023-11-08T12:31:36Z")

</div>

刚发现的写法，加入要判断用户有没有绑定手机号，有一个userInfo对象，内容可能是下面的某种

```js
var userInfo = {id: 1, mobile: null}
var userInfo = {id: 2, mobile: ""}
var userInfo = {id: 3, mobile: "15911110000"}

```

要判断用户有没有绑定手机号，就是判断mobile属性有没有非空的值，可以这样写。

```js
var bindMobileFlag = !!userInfo.mobile

```

非常的优雅好用啊。
