5. How JavaScript Is Executed | Complete JavaScript Tutorials

visibility 4 views schedule 5 years ago timer 3:15
open_in_new Dailymotion
Let's have a look at this interpreted on the fly compiled things<br />How is the javascript code in our browser.<br />Execute it and not just in our browser but typically in any environment where you run javascript let's<br />say you write your javascript code and you wanted to have some effect on the web page.<br />If we talk about the browser as the environment where we run our script then you have one important<br />thing built into any environment where you want to run javascript code.<br />And that's a JavaScript engine.<br />It's built into the browser as I said there and chrome for example in the Chrome browser.<br />It's the 8.<br />That's the name of the engine in Firefox.<br />The name would be spider monkey.<br />And of course our browsers also even reuse these engines or have their own engines.<br />Now the job of the engine is to pass code so pass read and understand your javascript code.<br />Then on the fly compile it to machine code because machine code executes faster.<br />So it reads your code but it does not necessarily executed like that but instead it now takes that code<br />and compiles it to code which is faster to execute by the machine and then it executes that machine<br />code.<br />This all happens in the browser with the help of the JavaScript engine.<br />And then when that code is executed we have that in fact on our Web page.<br />Now important modern engines have a lot of optimization stare.<br />They might start executing your uncle piled code and then compile the code whilst they're also already<br />executing it to get started executing faster and then switch to the compiled code dynamically ends on.<br />So we have a lot of optimizations going on here and we will dig a bit deeper into what the JavaScript<br />engine is.<br />Exactly.<br />In a separate module in the course for now it is is all we need to know the browser has a built in tool<br />that takes our code compiles it optimize it and executes it.<br />And also a little bit more technical side note all of that happens on a single threat.<br />Now this is very technical but you might know that in a computer you have certain tasks