Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
608 bytes
|
Line | |
---|
1 | /**
|
---|
2 | * Checks `value` to determine whether a default value should be returned in
|
---|
3 | * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
|
---|
4 | * or `undefined`.
|
---|
5 | *
|
---|
6 | * @static
|
---|
7 | * @memberOf _
|
---|
8 | * @since 4.14.0
|
---|
9 | * @category Util
|
---|
10 | * @param {*} value The value to check.
|
---|
11 | * @param {*} defaultValue The default value.
|
---|
12 | * @returns {*} Returns the resolved value.
|
---|
13 | * @example
|
---|
14 | *
|
---|
15 | * _.defaultTo(1, 10);
|
---|
16 | * // => 1
|
---|
17 | *
|
---|
18 | * _.defaultTo(undefined, 10);
|
---|
19 | * // => 10
|
---|
20 | */
|
---|
21 | function defaultTo(value, defaultValue) {
|
---|
22 | return (value == null || value !== value) ? defaultValue : value;
|
---|
23 | }
|
---|
24 |
|
---|
25 | module.exports = defaultTo;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.