0
votes
  1. With browsers which use the V8 JavaScript engine (JIT compilation), how much of the code is actually compiled into machine code and executed directly? Does it pick out bits or is the whole JavaScript compiled?

  2. Also, during the execution of the compiled code what would happen if I was to assign a function to an object in JavaScript? In typical languages this would be illegal, but I thought this flexibility within JavaScript came from the fact that it was interpreted so no illegal actions were technically executed? But if its compiled what happens in that scenario?

P.S

Sorry, what I mean is what would happen is this compiled code was executed "myObject = myFunction", assuming those variables were declared elsewhere. Would this be a legal assignment?

Many thanks in advance.

You can't edit a code while it's executing in javascript. Test it like this: Put a break into yoir javascript code in on e of the functions, then try to edit it. It won't work. - Bálint
Sorry, what I mean is what would happen is this compiled code was executed "myObject = myFunction", assuming those variables were declared elsewhere. Would this be a legal assignment? - Brummy
What exactly, do you think, does the assignment have to do with compilation? - a better oliver
I was thinking that this would break the program as things which use 'myObject' would now actually be accessing a function, and if its compiled rather than interpreted then the interpreter can't catch issues like this (and basically ignore them), if that makes sense? Maybe I'm thinking of it wrong. - Brummy
The compilation that v8 does is an optimization step. Since in JS objects are always passed by reference, if you somehow void that reference and overwrite the object with a different value - yes, your program will behave differently but that won't break v8 or the compilation it does. Your script will probably throw an error somewhere since instead of an object, you'll have something else. - Mjh