Message from JavaScript discussions

July 2017

— Like if you run var thing = "Hello" over and over, V8 actually will not re allocate memory for that string, it will re-use the existing one from memory...

Message permanent page


Now primitives are still copy-only, but until something edits the string it is very much the same exact memory location

— So if you can imagine... having knowledge of that during execution... powerful

— How is this a bad thing though?

— Oh, right

— We could say, for instance, that a variable assignment is the property of X scope, and do metaprogramming

Message permanent page

— And cross-scope, know exactly where it came from

— You could manage source code from a top-down perspective during runtime, idk the formal term but it would be like "self-aware JS"

Message permanent page

— Aaaah, like Lisp macros?

— A variable declaration is a directive to the parser to compute a scope and set a pointer to undefined for that variable until the line gets executed

Message permanent page

— So var thing = "hello", upon entry into a function call, runs code that allocates thing with undefined, then when it gets executed it simply swaps the pointer to the location in memory where the string is allocated

Message permanent page

— They're tagged pointers carrying the name of the variable, too