Is there a way to learn at how JavaScript is interpreted and executed? In .NET or JAVA for instance, you could look at the generated byte code, in C you could look at the generated assembly instruction but from what I gather, JavaScript is interpreted line by line and then it varies on the JS engine in different browsers.
Still is there a way to learn how JavaScript does this? Does the interpreter in modern browsers tend to look ahead and optimize as a compiler might?
For instance, if I did:
$('#div1').css('background-color','red');
$('#div1').css('color','white');
Could I have a perf gain by doing:
var x = $('#div1');
x.css('background-color','red');
x.css('color','white');
The point of this question is to get some information how one might gain some insight as to how JavaScript is run in the browser.
$('#div1').css({'background-color': 'red', 'color': 'white'});is the optimal solution because it's fewer bytes and they'll impact the loading of the JS file far more than the execution difference of the examples you provided.$('#div1')doesn't change between those two lines. You can't make those assumptions in an effectful language like JavaScript, and neither will a compiler.