# ReferenceError: variable is not defined - local variable within loop

**URL:** <https://discourse.psychopy.org/t/referenceerror-variable-is-not-defined-local-variable-within-loop/45500>\
**Category:** Online experiments\
**Created:** [August 30, 2025, 4:24pm UTC](https://discourse.psychopy.org/t/referenceerror-variable-is-not-defined-local-variable-within-loop/45500 "2025-08-30T16:24:48Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [August 30, 2025, 5:25pm UTC](https://discourse.psychopy.org/t/referenceerror-variable-is-not-defined-local-variable-within-loop/45500/2 "2025-08-30T17:25:55Z")

</div>

Hi. This should help.

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/41):
>
> ReferenceError: varName is not defined This is one of the most common errors in online experiments It is also one of the easiest to solve. The issue is one of “scope”. To define a variable so it has scope across your whole experiment, all you have to do is assign it a value. Don’t edit your JavaScript to add “var” or “let” commands. To give your variable scope assign the value in a Begin Experiment code component tab outside any clauses (i.e. no Python indents). I usually s…

---

_[View the full topic](https://discourse.psychopy.org/t/referenceerror-variable-is-not-defined-local-variable-within-loop/45500)._
