Is there a difference between .js files and event editor?

I was doing a few tests and I'm just curious about what's been happening. I've been declaring variables in .js files with:

var someVariable = someValue;Without the var keyword, someVariable would be undefined. When I went into the event editor and put these two lines in two different script blocks:

var anotherVariable = anotherValue;
Code:
console.log(anotherVariable);
There was an error saying that someVariable is not defined. I expected that. It worked fine when the two lines were in the same script block. However, when I split the lines into two blocks again and removed the var keyword: 

anotherVariable = anotherValue;
Code:
console.log(anotherVariable);
The console logged anotherValue! How are objects and variables in the event editor handled? I'm really confused about how anotherVariable could both be declared without var without being undefined and be used in other script blocks in the event editor.
Using var will bind the variable to the current scope. Not using var will make it global. Global variables are not a recommended way to store your information, as there are globals ready available for that.
further to the above, the two different script blocks do not have the same scope. The var you declared in the first one is not known to the second one, even though the two script calls are within the same event command. Once the first one is complete, the var ceases to exist.


If you wanted something you could share between them, you could try using this._someVariable to see if it will extend the scope to the Game_Interpreter object that's currently running. If that doesn't work, I'd just use a $gameVariable that's not already being used.
Thank you both for your responses! 
var is also very important in the aspect of "Strict" programming where doing no var makes the variable global and can cause issues down the road.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-difference-between-js-files-and-event-editor.49923/