You want the typeof
operator. Specifically:
if (typeof variable !== 'undefined') {
// the variable is defined
}
More Related Contents:
- JavaScript check if variable exists (is defined/initialized)
- How do JavaScript closures work?
- What is the scope of variables in JavaScript?
- Define a global variable in a JavaScript function
- How can I determine if a variable is ‘undefined’ or ‘null’?
- How to check a not-defined variable in JavaScript
- Calling a JavaScript function named in a variable [duplicate]
- Access variable outside function scope [duplicate]
- Is it better to return `undefined` or `null` from a javascript function? [closed]
- Use JavaScript variable as function name?
- Passing a local variable from one function to another
- Javascript: Get access to local variable or variable in closure by its name [duplicate]
- How to receive and maintain values in functions (javascript)
- How can I check for “undefined” in JavaScript? [duplicate]
- Is there a standard function to check for null, undefined, or blank variables in JavaScript?
- Set a default parameter value for a JavaScript function
- Javascript call() & apply() vs bind()?
- Is there a way to create a function from a string with javascript?
- this inside function
- Undefined values in Array(len) initializer
- Fastest JavaScript summation
- javascript : function and object…?
- Can you write nested functions in JavaScript?
- How does the location of a script tag in a page affect a JavaScript function that is defined in it?
- Multiple arguments vs. options object
- Vue: How do I call multiple functions with @click?
- How does the (function() {})() construct work and why do people use it?
- Count of “Defined” Array Elements
- Print / display a JavaScript variable’s name instead of it’s value
- What is the difference between onClick=”javascript: function(‘value’)'” and onClick=”function(‘value’);”? [duplicate]