Local and Global Variable Declarations
Variables declared using the var keyword are local variables, which persist only for the lifetime of the scope in which they are declared. Top-level local variables in your script are deleted when the script returns. However, variables declared without the var keyword become properties of the global object. Global variables and their data persist between calls to your script.
To avoid unintended consequences, such as memory leaks or security breaches, use local variables by declaring them using the var keyword:
var count = 0; //Local variable declaration
filter = new AttributeFilter(); //Persistent global property