You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
608 B

4 years ago
  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. module.exports = defaultTo;