# Jacascript reference error hero not defined

**URL:** <https://discourse.codecombat.com/t/jacascript-reference-error-hero-not-defined/7827>\
**Category:** Bugs\
**Created:** [June 1, 2016, 1:07am UTC](https://discourse.codecombat.com/t/jacascript-reference-error-hero-not-defined/7827 "2016-06-01T01:07:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gypsyrose](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@Gypsyrose](https://discourse.codecombat.com/u/Gypsyrose)\
**Post date:** [June 1, 2016, 1:07am UTC](https://discourse.codecombat.com/t/jacascript-reference-error-hero-not-defined/7827/1 "2016-06-01T01:07:40Z")

</div>

I am getting a red message that says that the hero is not defined, and to try a placeholder. I cannot figure out how to get past that.  
The program was working fine yesterday, but started this today.  
It is also reading that message on the levels I have already passed.  
Can someone help me to get past this?

---

<div class="post-metadata">

**Author:** ![trotod](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/trotod/32/3263_2.png) [@trotod](https://discourse.codecombat.com/u/trotod)\
**Post date:** [June 1, 2016, 1:30am UTC](https://discourse.codecombat.com/t/jacascript-reference-error-hero-not-defined/7827/2 "2016-06-01T01:30:57Z")

</div>

Seeing this error too. Maybe it was a botched deploy.

You can get around it in JavaScript by adding the following snippet to the top of your code:

```javascript
if (typeof hero === 'undefined') var hero = this;

```

Basically it checks to see if the `hero` variable is not defined, and if so, assigns the value of `this` (which also refers to the hero) to `hero`.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [June 1, 2016, 1:50pm UTC](https://discourse.codecombat.com/t/jacascript-reference-error-hero-not-defined/7827/3 "2016-06-01T13:50:53Z")

</div>

Do you still see it if you clear your cache and reload?

---

<div class="post-metadata">

**Author:** ![trotod](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/trotod/32/3263_2.png) [@trotod](https://discourse.codecombat.com/u/trotod)\
**Post date:** [June 2, 2016, 3:20am UTC](https://discourse.codecombat.com/t/jacascript-reference-error-hero-not-defined/7827/4 "2016-06-02T03:20:54Z")

</div>

The error seems to be fixed for me now.
