Javascript Engine

JAVASCRIPT ENGINE

 
  • Javascript is a single threaded language.
  • Whenever you write the js code, the js file is given to JS engine. And JS engine understands the js file. It tells the machine to do what we have asked to do with this piece of code.
  • There are so many engines
    • SpiderMonkey
    • Chakra
    • V8 engine
      • V8 was released by google in 2008
      • V8 is written in c++
      • They came up with this engine to overcome the performance for google maps.
    • etc….
  • v8 is the most popular and common.
 
 
  • JS file we get first
  • Lexical scoping is done
  • code is broken int tokens
  • These tokens are formed to AST (asbstract syntax tree).
  • Then it goes to interpreter, profiler, compiler. Finally the optimized code is sent to the system.
  • Becuase everybody can create their own js engine. So we dont call it as js engine. Rather we call it as ECMAScript engines. ES Engine follows ECMAscript standard.

        Interpreters and Compilers

  •  In programming there are two ways to traslate to machine code which our computers can understand
    • Interpreter – It translates line by line
    • Compilers – Understands the code , and writes the code altogether in a different language ,  a low level language. Then that is served to machine.
  • Interpreter – is quick. It no needs to convert to another language. No compilation steps to run your code.
  • Javascript used interpreters at the beginning
  • There is a disadvantage of using interpreter. The same issue happened back in 2008 when google were using the google maps. For example if you are running a same piece of code in a loop and we are expecting the same result everytime. Interpreter will be damn slow as it does line by line reading. It has no way to optimize the code. 
  • But compiler can simplify the code and optimize it. But compiler takes lot of time to get up and running.
  • Both has their pros and cons
  • So we need best of both the world.
  • Combine both – JIT compiler – just in time compiler
 

Leave a Comment