Posts

Showing posts from December, 2021

Hoisiting

Define -: Accessing a variable before defining it without getting an error. 1.Variable console.log("x",x) var x= 7; it will print undefined. 2.Function  console.log(fun) function fun() { console.log("HELLO") } it will print the function itself. 3.Arrow Function arrow function behaves like a variable and it will say function is not defined or declared if we access it before define.

What happens when you run javascript code?

First of all execution context is created. It allocates memory to variable and it's value as undefined in the first phase  and then any function if available it's entire code and then function calls as values of undefined . Now in second phase comes the code execution. one by one the code will be executed. now variables real values are assigned instead of undefined . now it runs next code . and now if any function call is present it will now run them. and again new execution context will be created   for the function in the global execution  context(the outer and first execution ) and same process with be done. after completion execution context will be deleted. call stack -: the global execution context is pushed inside the call stack. now next ec will go to call stack and once this is done will be popped out. and control goes again gec and next ec will be pushed. call stack maintains the order of execution  of execution contexts .
 How Javascript Works Everything in javascript happens  inside Execution Context . Execution  Context  is like a big box. It has memory(variable environment) and code(thread of Execution  ). memory stores all variable and functions in key value pair form .  and on thread code is executed line by  line. javascript is synchronous single threaded language . It means javascript can execute one command at a time in specific  order. it will only go to next line once the current command is executed .