I have an if statement, which ideally I'd like to check the value of a variable, only if THAT variable exists. This is not just checking whether a variable exists (e.g. by using typeof()), but preventing an attempt to check what the value of the variable is if it doesn't exist. My if statement looks something like this:
variable_1 = "I am now being defined";
// in an instance where value_2 has not been defined
if( variable_1 == "value_1" &
variable_2 == "value_2"){
// code to execute
}
however, sometimes variable_2 won't have been defined, and so I get the error "variable_2 is not defined". Is there an elegant way to check if variable_2 exists, and if it does exist check what its value is?
Thanks is advance! Apologies if I've overlooked something basic.