Check if varibale is defined - dynamic Var

Viewed 20

How can i check if a dynamic var is defined?

var num=2;
var foo2=true

if (typeof ('foo'+num)!="undefined"){
return 1
}
1 Answers

Using the eval statement.

var num = 2;

var con = 'foo' + num
console.log(eval("typeof " + con + " === 'undefined'"))

Related