Answers for "js how to test if a variable exist"

15

javascript check if variable exists

if (typeof myVar !== 'undefined') {
    // myVar is defined
}
Posted by: Guest on July-23-2019
1

How can I test whether a variable has a value in JavaScript?

if (typeof variable == "undefined") {...} --> return true if variable undefined

//An empty string evaluates to FALSE in JavaScript so you can just do:
if (variable) {...}
Posted by: Guest on December-03-2020

Code answers related to "js how to test if a variable exist"

Code answers related to "Javascript"

Browse Popular Code Answers by Language