---
layout: page
title: "JavaScript isset function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/isset:454
- /functions/view/isset
- /functions/view/454
- /functions/isset:454
- /functions/454
---
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's isset

{% codeblock var/isset.js lang:js https://raw.github.com/kvz/phpjs/master/functions/var/isset.js raw on github %}
function isset () {
  // From: http://phpjs.org/functions
  // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // +   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,
    undef;

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

  while (i !== l) {
    if (a[i] === undef || a[i] === null) {
      return false;
    }
    i++;
  }
  return true;
}
{% endcodeblock %}

 - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/var/isset.js)

Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are 
the closest match to this hashtable-like data structure. 

Please also note that php.js offers community built functions and goes by the 
[McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online 
functions that are far from perfect, in the hopes to spark better contributions. 
Do you have one? Then please just: 

 - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/var/isset.js)

### Example 1
This code
{% codeblock lang:js example %}
isset( undefined, true);
{% endcodeblock %}

Should return
{% codeblock lang:js returns %}
false
{% endcodeblock %}

### Example 2
This code
{% codeblock lang:js example %}
isset( 'Kevin van Zonneveld' );
{% endcodeblock %}

Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}


### Other PHP functions in the var extension
{% render_partial _includes/custom/var.html %}
