less than 1 minute read

TIL that global variables are automatically (magically?) set on window in javascript.

Example:

<script>
    global_id = 4;
</script>

Is equivalent to:

<script>
    window.global_id = 4;
</script>

I also learned that the javascript “this” keyword, when used outside of a closure, also refers to window. Neat!

Updated:

Comments