> For the complete documentation index, see [llms.txt](https://heihei12305.gitbook.io/my-underscore/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heihei12305.gitbook.io/my-underscore/han-shu-pan-duan-yu-js-zhong-de-+-jia-zhi.md).

# 函数判断与Js中的’&& ||‘+假值

```
 _.isFunction = function(obj){
    return typeof obj == 'function' || false;
}
```

就是简单判断一个函数而已，不过可以扩展出一个知识点嘿嘿，<br>

你是怎么看js中的`&&,||`？<br>

与其说是逻辑运算符，不如说是属性选择符。

* `&&`执行方式（a&\&b）：
  * 如果a为true，返回b
  * 否则返回a
* `||`执行方式（a || b）:
  * 如果a为true, 返回a
  * 否则返回b

```
'' || [1,2] //[1,2]
'' && [1,2] //""

[1] || [] //[1]
[1] && [] //[]
```

然后把js中为false的属性整理一下啦：&#x20;

\
&#x20;ES5规范9.2定义了抽象操作ToBoolean,列举了布尔强制类型转换所有可能出现的结果。

* undefined
* null
* false
* +0,-0 和 NaN
* ""

从逻辑上说，假值列表以外的都应该是真值。<br>

* 除了'',其他的字符串都是真值。

```
let a  = 'false';
let b = '0';
let c = "''";

let d = Boolean(a && b && c );
d; // true
```

* `[],{},fucntion(){}`都不在假值列表里，所以他们都是真值。

```
let a  = [];
let b = {};
let c = function(){};

let d = Boolean(a && b && c );
d; // true
```

真值列表是无限长的，我们只能根据假值列表作为参考，可以理解位假值列表以外的值都是真值。

* 常用的 || 用法：设置默认值

```
function foo(a,b){
    a = a || 'hello';
    b = b || 'world';

    console.log(a + ' ' + b);
};

foo(1);// '1 world'
```

* js代码压缩工具常用的‘守护运算符’：

```
function foo(){
    console.log(a);
};

let a = 1;
a && foo(); 
//当第一个操作数为真值时，&&才会选择第二个操作数作为返回值，即前面的表达式为后面的表达式'把关'
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://heihei12305.gitbook.io/my-underscore/han-shu-pan-duan-yu-js-zhong-de-+-jia-zhi.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.
