gautamlakum gautamlakum - 1 year ago 92
Javascript Question

is there something like isset of php in javascript/jQuery?

Is there something in javascript/jQuery to check whether variable is set/available or not? In php, we use

to check something like this.


Answer Source

Try this expression:

typeof(variable) != "undefined" && variable !== null

This will be true if the variable is defined and not null, which is the equivalent of how PHP's isset works.

You can use it like this:

if(typeof(variable) != "undefined" && variable !== null) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download