Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  152] [ 3]  / answers: 1 / hits: 105303  / 15 Years ago, thu, april 2, 2009, 12:00:00

i feel like im trying to do something super simple, but just being stupid about it.



all i want to do is see if a variable has been set previously, and if it has NOT, set it with a default value....here is a sample:



if(!embed_BackgroundColor) {
var embed_BackgroundColor;
embed_BackgroundColor = #F4F4F4;
}


so, once you stop laughing at my code....WHY is it overwriting the variable no matter what?



please save my nerves;)


More From » variables

 Answers
12
if (typeof variable === 'undefined') {
// variable is undefined
// eg:
// var variable = someValue;
}

[#99755] Sunday, March 29, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stephonkeandrer

Total Points: 392
Total Questions: 94
Total Answers: 100

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
;