5. How JavaScript Is Executed | Complete JavaScript Tutorials

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

Recommended