The BobSprite Raw Blog


Pixel Art, Programming and Video Games

(click here and go to index)

JavaScript Programmers Can't Stand on top

The catch of an innocent identifier as global variable

On the top
On the top


Please, before you throw anything at me, take a look at the code below.

*      *      *

You can't stand on top

On the top
Testing "top" as global variable

You can open Testing "top" as Global Variable Identifier.

Chrome: ErrorUncaught TypeError: Cannot assign to read only property 'top' of object '#<Window>' ...
Firefox: Uncaught TypeError: setting getter-only property "top" <anonymous> ...

*      *      *

Standing on bottom is OK

On the top
Testing "bottom" as global variable

You can open Testing "bottom" as Global Variable Identifier.
*      *      *

Notes


You may use "top" to name a local variable (declared inside a function), but not to name a global variable (declared outside a function).

But its "inferior" friend, "bottom" you can use as local and as global variable name.

*      *      *
This article was made using


*      *      *
I had a bad time in the past because Chrome (old version)
  1. allowed me to declare "top" as global variable
  2. silently rejected the assignment to global variable "top"

A bad time...