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
输出