# Check to see if a variable has been created

**URL:** <https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116>\
**Category:** flash\
**Created:** [May 23, 2008, 9:33am UTC](https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116 "2008-05-23T09:33:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rabasaurus](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@Rabasaurus](https://forum.kirupa.com/u/Rabasaurus)\
**Post date:** [May 23, 2008, 9:33am UTC](https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116/1 "2008-05-23T09:33:53Z")

</div>

Hey folks, need some of your expert help.

Im creating an online survery and recording all the answers as a variable in \_root.vars.variablename where each question creates a new variable in the vars clip.

When the user answers a question the variable is created and given a value e.g.

\_root.vars.variablename1 = 1  
\_root.vars.variablename2 = 1  
\_root.vars.variablename2 = 0

But I need a piece of code to check if the variable has actually been created. The reason for this is I have a next button the user has to click once they have answered, and I dont want them to advance if they havent answered. So I need to add something like if (\_root.vars.variablename1 exists ) {gotoAndPlay(“answered”);} else{ gotoAndPlay(“noAnswer”);}

Obviously the code above is wrong, I just need something to replace the ‘exists’.

Any help appreciated!!

---

<div class="post-metadata">

**Author:** ![Rabasaurus](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@Rabasaurus](https://forum.kirupa.com/u/Rabasaurus)\
**Post date:** [May 23, 2008, 10:21am UTC](https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116/2 "2008-05-23T10:21:04Z")

</div>

No worries folks, got it sorted!

if (\_root.vars.gender !== undefined) {

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [May 23, 2008, 10:33am UTC](https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116/3 "2008-05-23T10:33:31Z")

</div>

> !==  
> ???

> !=

I am sure

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [May 23, 2008, 11:13am UTC](https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116/4 "2008-05-23T11:13:17Z")

</div>

Why don’t you just set the questions up as an array and have the array elements store ‘false’ if the question hasn’t been answered and ‘true’ if it has. That way you don’t need to keep declaring variables for each new question.

---

<div class="post-metadata">

**Author:** ![Rabasaurus](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@Rabasaurus](https://forum.kirupa.com/u/Rabasaurus)\
**Post date:** [May 23, 2008, 11:19am UTC](https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116/5 "2008-05-23T11:19:27Z")

</div>

[quote=randomagain;2330006]???

I am sure[/quote]

Ooops, fixed that!

And we cant store questions as true / false as some are multiple choice, multiple select and text entry.

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [May 23, 2008, 2:37pm UTC](https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116/6 "2008-05-23T14:37:40Z")

</div>

!= and !== are essentially the same thing. != a.k.a. the inequality operator, when being used, converts data types (to strings) to check for inequality; thus 2 != “2” will return false whereas !== a.k.a. the _strict_ inquality operator _does_ take data types into account; thus 2 !== “2” will return _true_ as **both** of the values aren’t number

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [May 24, 2008, 9:27am UTC](https://forum.kirupa.com/t/check-to-see-if-a-variable-has-been-created/261116/7 "2008-05-24T09:27:31Z")

</div>

Ok store questions as 1/2/3/4/5 and 0

0 being unanswered and 1/2/3/4/5 being the choice. Just saves having to declare vars
