Lodash教程

Lodash defaultTo method

语法

_.defaultTo(value, defaultValue)
Checks value to determine whether a default value should be returned in its place. The defaultValue is returned if value is NaN, null, or undefined.

参数

value (*) − The value to check. defaultValue (*) − The default value.

输出

(*) − Returns the resolved value.

实例

var _ = require('lodash');
var result = _.defaultTo(5, 6);
 
console.log(result);
 
result = _.defaultTo(undefined, 6); 
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

5
6
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4