- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
Lodash - defaultTo method
Syntax
_.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.
Arguments
value (*) − The value to check.
defaultValue (*) − The default value.
Output
(*) − Returns the resolved value.
Example
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
Output
5 6
lodash_util.htm
Advertisements