HTHyperTransformer AI

Study cards › JavaScript & TypeScript

JavaScript & TypeScriptInterview questions and answers

← Topics1 / 100
1 / 100 viewed
Question

What is an execution context in JavaScript?

Answer

An execution context is the environment where a piece of code runs. It holds the variable environment (declared vars/functions), the scope chain (which outer scopes are visible), and the value of 'this'. JS creates a new context for the global code, every function call, and every eval invocation.

Question

What is the call stack?

Answer

The call stack is a LIFO (last-in, first-out) stack of execution contexts. When you call a function, a frame is pushed; when it returns, the frame is popped. If frames pile up faster than they pop (e.g. unbounded recursion), you get a 'Maximum call stack exceeded' error.

Question

What is the event loop?

Answer

The event loop is the mechanism that takes callbacks from the task and microtask queues and pushes them onto the call stack — but only when the stack is empty. This is how single-threaded JavaScript handles async work without blocking: heavy callbacks wait their turn instead of running mid-stack.

Question

Microtasks vs macrotasks?

Answer

Microtasks are queued by promises, queueMicrotask, and MutationObserver. Macrotasks come from setTimeout, setInterval, I/O, and UI events. All pending microtasks drain fully BEFORE the next macrotask runs — which is why promise callbacks always run before a setTimeout(…, 0).

Question

What is a closure?

Answer

A closure is a function that retains access to variables from its outer (lexical) scope even after the outer function has returned. Example: function outer(){ let n=0; return ()=>++n }. Each call to outer() creates a fresh n, captured by the inner function — closures power private state, currying, and memoization.

95 more JavaScript & TypeScript cards

Sign in with Google to study the whole deck, flag tricky answers and track your progress.

Continue with Google

More topics: React & Frontend Backend Engineering Databases System Design AI & Agentic AI DevOps & Cloud Security Testing DSA Coding Problems (Python)