You want the typeof
operator. Specifically:
if (typeof variable !== 'undefined') {
// the variable is defined
}
Related Contents:
- JavaScript check if variable exists (is defined/initialized)
- How do JavaScript closures work?
- How can I determine if a variable is ‘undefined’ or ‘null’?
- What is the scope of variables in JavaScript?
- How to check a not-defined variable in JavaScript
- Define a global variable in a JavaScript function
- Check if object exists in JavaScript
- Calling a JavaScript function named in a variable [duplicate]
- Is it better to return `undefined` or `null` from a javascript function?
- How to pass the value ‘undefined’ to a function with multiple parameters?
- Typescript – TypeError myclass.myFunction is not a function
- What is the difference between null and undefined in JavaScript?
- Is there a better way to do optional function parameters in JavaScript? [duplicate]
- JavaScript checking for null vs. undefined and difference between == and ===
- How to check for an undefined or null variable in JavaScript?
- Declaring multiple variables in JavaScript
- How to turn a String into a JavaScript function call? [duplicate]
- Is it possible to get all arguments of a function as single object inside that function?
- How to check if a JavaScript variable is NOT undefined? [duplicate]
- How to create a jQuery function (a new jQuery method or plugin)?
- Cannot read property ‘addEventListener’ of null
- Extending an Object in Javascript
- JavaScript null check
- Calling dynamic function with dynamic number of parameters [duplicate]
- Global variables in Javascript and ESLint
- JavaScript function order: why does it matter?
- In Javascript/jQuery what does (e) mean?
- Dynamic function name in javascript?
- Javascript: Extend a Function
- Adding console.log to every function automatically
- Call Python function from JavaScript code
- `new function()` with lower case “f” in JavaScript
- Declaring functions in JavaScript [duplicate]
- Can I name a JavaScript function and execute it immediately?
- Javascript: Call a function after specific time period
- How to pass a list from Python, by Jinja2 to JavaScript
- How can I make a program wait for a variable change in javascript?
- Vanilla JavaScript version of jQuery .click
- javascript: define a variable if it doesn’t exist
- javascript pass object as reference
- How to change onClick handler dynamically?
- Unlimited arguments in a JavaScript function
- JavaScript `undefined` vs `void 0`
- Passing a function with arguments as an argument?
- Passing parameters to a JQuery function
- Can global constants be declared in JavaScript?
- Redeclaring a javascript variable
- Javascript: “Infinite” parameters for function?
- When should I use let and var? [closed]
- How do I write a jquery function that accepts a callback as a parameter