DEV Community

Discussion on: Javascript call by value or by reference, actually by sharing

 
kingychiu profile image
Anthony Chiu

Thanks for your reply, let me study more with the given directions.

My imdidate response to this

Remember that the runtime is free to optimize whichever way it seems fit as long as the observable behaviour aligns with the language specification.

Yeah, it makes a lot of sense. For example, in C/C++, the "Optimization" I learned is like out-of-order execution (including speculation) and unfolding loops. I remember back then, I was shocked as well. Now I realize it is not just the JavaScript tutorials problem. One of the utimate problems is that the teaching materials don't separate what the language specifications are. But for non-specified behaviors, they are subjected to be changed/optimized. I think this is also a missing mental model puzzle here.

Back then, our university C++/Java course should also focus more on the language specifications first and make a clear separation between abstraction and implementation. Now I am confused about what I have learned (for all languages what their specifications/promises are).