# defined

> return the first argument that is `!== undefined`

Latest version **1.0.1** (published 2022-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install defined
pnpm add defined
yarn add defined
bun add defined
```

## Health

**Score 33/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-10-12 |
| First published | 2012-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/defined) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | James Halliday |
| Maintainers | substack, ljharb |
| Keywords | undefined, short-circuit, \|\|, or, //, defined-or |

## Links

- npm: https://www.npmjs.com/package/defined
- Repository: https://github.com/inspect-js/defined
- Issues: https://github.com/inspect-js/defined/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/defined

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2022-10-12
- 1.0.0 — 2015-04-08
- 0.0.0 — 2012-11-26

## README

# defined <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

return the first argument that is `!== undefined`

Most of the time when I chain together `||`s, I actually just want the first
item that is not `undefined`, not the first non-falsy item.

This module is like the defined-or (`//`) operator in perl 5.10+.

# example

``` js
var defined = require('defined');
var opts = { y : false, w : 4 };
var x = defined(opts.x, opts.y, opts.w, 100);
console.log(x);
```

```
$ node example/defined.js
false
```

The return value is `false` because `false` is the first item that is
`!== undefined`.

# methods

``` js
var defined = require('defined')
```

## var x = defined(a, b, c...)

Return the first item in the argument list `a, b, c...` that is `!== undefined`.

If all the items are `=== undefined`, return undefined.

# install

With [npm](https://npmjs.org) do:

```
npm install defined
```

# license

MIT

[package-url]: https://npmjs.org/package/defined
[npm-version-svg]: https://versionbadg.es/inspect-js/defined.svg
[deps-svg]: https://david-dm.org/inspect-js/defined.svg
[deps-url]: https://david-dm.org/inspect-js/defined
[dev-deps-svg]: https://david-dm.org/inspect-js/defined/dev-status.svg
[dev-deps-url]: https://david-dm.org/inspect-js/defined#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/defined.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/defined.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/defined.svg
[downloads-url]: https://npm-stat.com/charts.html?package=defined
[codecov-image]: https://codecov.io/gh/inspect-js/defined/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/defined/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/defined
[actions-url]: https://github.com/inspect-js/defined/actions

---
_Source: https://npm.io/package/defined · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
