Zerotomastery JS advanced Flashcards
Which engine google chrome uses ?
V8 developed by google. Also used by node js
Which language V8 is written ?
C++
is JS interpreted language ?
Depends on the engine. Different engines handle it differently. But initially yes when JS first came out we had SpiderMonkey (still have) which Firefox uses created by Brendon Iche that interpreted javascript to bytecode. But things have envolved now.
We don’t have just interpreters. We also use compilers to optimize our code.
So this is a common misconsooption
methods, and things which are bad for optimization
- eval()
- arguments
- for in
- with
- delete
bad for inline caching and hidden classes
what is inline caching and give me then example
so if function is called multiple times with same input then compiler do optimization and do caching so it will not look up the input every single time. In order to write a optimizable code that engine can do, we have to write a predictible code. Don’t do surprises. Don’t confuse the compiler
What is heap memory
Heap memory is a place where JavaScript stores objects and functions.
When you create a variable and assign it a primitive value, it will be stored in stack. Something different happens when you try the same, but with an object. When it comes to the object itself, JavaScript will store it in the memory heap. That variable that exists in the stack will only point to this object in memory heap.
What is call stack
A call stack is a mechanism for an interpreter (like the JavaScript interpreter in a web browser) to keep track of its place in a script that calls multiple functions — what function is currently being run and what functions are called from within that function, etc. First in last out
- When a script calls a function, the interpreter adds it to the call stack and then starts carrying out the function.
- Any functions that are called by that function are added to the call stack further up, and run where their calls are reached.
- When the current function is finished, the interpreter takes it off the stack and resumes execution where it left off in the last code listing.
- If the stack takes up more space than it had assigned to it, it results in a “stack overflow” error.
What is garbage collection in js
Some high-level languages, such as JavaScript, utilize a form of automatic memory management known as garbage collection (GC). The purpose of a garbage collector is to monitor memory allocation and determine when a block of allocated memory is no longer needed and reclaim it.
what is a memory leak
A Memory leak can be defined as a piece of memory that is no longer being used or required by an application but for some reason is not returned back to the OS.In simple terms it is forgotten data forever waiting to be used.Leaks are the cause of whole class of problems: slowdowns, crashes, high latency, and even problems with other applications.
What is js runtime and web APIS
Js runtime is where your code is being exacuting in. Web API is your browsers methods that we are using. They are all async.
E: settimout, fetch.
Common ways to cause memory leak
Global variables
EventListeners and not removing them
Setinterval
What is exacution context ?
The Execution Context contains the code that’s currently running, and everything that aids in its execution. During the Execution Context run-time, the specific code gets parsed by a parser, the variables and functions are stored in memory, executable byte-code gets generated, and the code gets executed.
What is lexical environment?
Lexical Environment is the environment of the function where it is written. That is, the static order/place where it is situated, regardless from where it is called from.
Scope of a variable/function is basically the locations from where a variable is visible/accessible.
Execution context is the status of the execution stack at any point during runtime. That is the current execution context
What is scope
Scope is the area of the program where an item (be it variable, constant, function, etc.) that has an identifier name is recognized. In our discussion, we will use a variable and the place within a program where the variable is defined determines its scope.
What is a scope chain
Scope chains establish the scope for a given function. Each function defined has its own nested scope, and any function defined within another function has a local scope which is linked to the outer function — this link is called the chain.