Posts

Showing posts with the label javascript

JavaScript Engine

Image
JavaScript can run everywhere because of JavaScript Runtime Environment. It is like a container which has everything inside it required to run a JavaScript code. JavaScript engine is the most significant part of JSRE. All browsers have their own JSRE which helps them in executing the JS code. JavaScript Engine It is neither a software or a hardware, it is a program written in low level language. Some of the popular JS engines are -  V8 from  Google . SpiderMonkey  is developed by  Mozilla  for use in Firefox and its forks. JavaScriptCore  is  Apple's engine for its Safari browser. Chakra  is the engine of the  Internet Explorer  browser. It was also forked by Microsoft for the original Edge browser, but Edge was later rebuilt as a Chromium-based browser and thus now uses V8. JavaScript can behave like both interpreted and compiled language. It simply depends on JavaScript Engine. In case o...

Hoisting in JavaScript

Image
Hoisting is a phenomenon in JavaScript, in which we can access variables and functions without any error before their initialization. This happens because even before the code starts executing, memory is allocated to variables and functions. JavaScript is synchronous and single threaded language where everything happens inside a Global Execution Context. When we run a JS program, an execution context is created, which is further divided into two phases: Memory Allocation Phase (Variable Environment) Code Execution Phase (Thread of Execution) In the first phase, the entire program is skimmed line by line and memory is allocated to functions and variables. In case of variables, undefined is stored as a placeholder and in case of functions, the whole code of function is stored. In the second phase, the code is actually executed line by line. Undefined keyword is now replaced by actual values of variables. When there is a function invocation, a entirely new execution context is created whi...