Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including defined with all npm packages installed. Try it out:

var defined = require("defined")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

defined v1.0.0

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


return the first argument that is !== undefined

browser support

build status

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+.


var defined = require('defined');
var opts = { y : false, w : 4 };
var x = defined(opts.x, opts.y, opts.w, 100);
$ node example/defined.js

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


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.


With npm do:

npm install defined



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free