Fork me on GitHub

Learn how to do it in JavaScript. Explore boundaries porting languages. Enjoy functions that turn out to be useful.

Here’s what a JavaScript equivalent for PHP’s isset looks like.

function isset () {
  //  discuss at:
  // original by: Kevin van Zonneveld (
  // improved by: FremyCompany
  // improved by: Onno Marsman
  // improved by: Rafał Kukawski (
  //   example 1: isset( undefined, true);
  //   returns 1: false
  //   example 2: isset( 'Kevin van Zonneveld' );
  //   returns 2: true

  var a = arguments,
    l = a.length,
    i = 0,

  if (l === 0) {
    throw new Error('Empty isset')

  while (i !== l) {
    if (a[i] === undef || a[i] === null) {
      return false
  return true
View on GitHub Edit on GitHub Source on GitHub

A community initiative

php.js offers community built functions and goes by the McDonald’s Theory. We’ll put online functions that aren't perfect, in the hopes to spark better contributions. Do you have one? You can directly edit this file on GitHub, this will create a Pull Request that the core team can review, and merge into our codebase.

This way of working also means that we don't offer any production guarantees, and recommend to use php.js inspiration and learning purposes only.

Example 1

isset( undefined, true);
Should return:

Example 2

isset( 'Kevin van Zonneveld' );
Should return:

« More var functions