![]() |
VOOZH | about |
JavaScript is a lightweight, interpreted, single-threaded, and cross-platform programming language for building dynamic web applications.
In this advanced section, we focus on senior-level JavaScript Interview Questions. These go beyond syntax and cover how JavaScript actually executes: strict mode rules, closure lifetimes, cross-realm quirks, precise DOM behavior, and the real order of async operations in the event loop.
Strict Mode is a new feature in ECMAScript 5 that allows you to place a program or a function in a "strict" operating context. This strict context prevents certain actions from being taken and throws more exceptions. The statement "use strict" instructs the browser to use the Strict mode, which is a reduced and safer feature set of JavaScript.
In JavaScript, checkboxes can have three different states that developers need to understand: checked, indeterminate, and form submission value. Each plays a distinct role in how checkboxes behave in the browser.
true or false) that shows if a checkbox is currently selected. Affects form submission.value attribute (default "on") is submitted. If unchecked, nothing is submitted.Example:
In this example:
subscribe=yescheckedThe closure is created when a child functions to keep the environment of the parent's scope even after the parent's function has already been executed. The Closure is a locally declared variable related to a function. The closure will provide better control over the code when using them.
instanceofis realm-specific: it checks whether Ctor.prototype (from that exact global/iframe) appears in the value’s prototype chain. Since each iframe has its own global objects and prototypes, an array (or Error, Map, DOM node, etc.) created in iframe A will usually fail value instanceof Array tested in iframe B—even though it’s “an array.” This makes instanceof unreliable across iframes/workers/realms.
window.postMessage() work across origins? What are structured clones vs transferable objects?window.postMessage() is a safe way to communicate between different windows, tabs, iframes, or workers, even if they have different origins. It works by sending a message event from one window to another, where the receiving window listens with an onmessage handler. Security is controlled by the targetOrigin parameter, which ensures that only messages from trusted origins are accepted.
otherWindow.postMessage(message, targetOrigin) sends data between windows or iframes. The browser checks targetOrigin so only trusted origins receive the message.ArrayBuffer or MessagePort, can be transferred instead of cloned. Ownership is moved to the receiver, and the original becomes unusable, which improves performance.Error.cause in ES2022.In modern JavaScript, error handling has improved with features that make debugging and maintaining code easier. Three important aspects are custom error classes, async stack traces, and the Error.cause option introduced in ES2022.
Error class to define specific error types. This makes it easier to categorize and handle errors.async/await. If an error happens deep inside an awaited function, the stack trace shows the full async call chain, which makes debugging asynchronous code clearer.cause option lets you attach the original error when throwing a new one. This preserves context and makes nested errors easier to debug.queueMicrotask, MutationObserver,MessageChannel, setTimeout(0), and await inside an async function?In JavaScript, the event loop carefully decides the order in which tasks run.
[ , , 3]), how iteration methods skip holes, and the difference with undefined.In JavaScript, arrays can be sparse, meaning they have “holes” where no value or property exists. This behavior differs from explicitly assigning undefined.
[ , , 3 ] has a length of 3 but only an element at index 2. Indexes 0 and 1 are holes (no value stored).forEach, map, filter, reduce) skip holes, while methods like for...in, for...of, and Array.keys() will see the index positions.undefined: A hole is the absence of a property, while undefined is an explicit value.Example:
getElementsByClassName, querySelectorAll, and the live vs static behavior of NodeList.JavaScript provides different DOM selection methods, and they differ in whether their results stay updated when the DOM changes.
HTMLCollection. If new elements with that class are added or removed, the collection updates automatically.NodeList. It is a snapshot at the time of the query and does not update if the DOM changes.Example:
innerText vs textContent: layout thrashing, performance, and security implications.Both innerText and textContent return or set the text of a DOM element, but they behave differently in terms of rendering, speed, and safety.
display: none or text-transform). Accessing it triggers reflow and layout calculations, which can cause layout thrashing and hurt performance.innerHTML, not textContent or innerText, is the unsafe methodConsider a situation an element is present inside another element and both of them handle an event. When an event occurs in bubbling, the innermost element handles the event first, then the outer, and so on.
delete obj.prop, obj.prop = undefined, and Reflect.deleteProperty() — when does GC actually free memory?In JavaScript, object properties can be removed or set to undefined, but these actions behave differently and affect garbage collection only in specific cases.
prop is no longer in the object. If nothing else references the value, it becomes eligible for garbage collection.undefined as its value. The property still exists, and the old value can only be garbage-collected if no other references remain.delete obj.prop, but returns a boolean result (true if deletion succeeded). It is preferred in modern code for consistency with Reflect methods.undefined does not guarantee immediate GC, but both allowJavaScript is the main language that has to maintain some rules and regulations which is ECMA Script, these rules also bring new features for the language JavaScript.
Modern JavaScript development often deals with differences in browser support. Progressive enhancement, feature detection, and polyfills are strategies to ensure compatibility and graceful fallback.
typeof, the in operator, or try/catch around API usage.Array.prototype.includes in environments that only support indexOf.In this example, If you use Array.prototype.includes in your code and run it in an old browser, it would normally throw an error because the method does not exist. With a polyfill, the method is defined using older functionality (indexOf). This way, modern code can run safely even in older environments.
delete obj.prop, obj.prop = undefined, and Reflect.deleteProperty(obj, "prop")? How do these affect GC, and why can’t you delete a let or const binding?delete obj.prop: Removes the property from the object. Value can be garbage-collected if no other references exist.obj.prop = undefined: Keeps the property key but sets its value to undefined. Old value can be GC’d if unreferenced.Reflect.deleteProperty(obj, "prop"): Same as delete, but returns a boolean success flag.let/const: They are block-scoped bindings, not object properties, so delete cannot remove them.==). How does JavaScript coerce types in cases like "0" == 0, false == [], null == undefined, and [] == ![]? Why does TC39 recommend Object.is or === instead?The loose equality operator == uses the Abstract Equality Comparison Algorithm, which performs type coercion before comparing values.
"0" is converted to number 0, result is true.false becomes 0, [] becomes "" then 0, result is true.true.![] is false which becomes 0, [] becomes "" then 0, result is true.Why avoid ==: These coercions cause confusing results. TC39 recommends === or Object.is for strict, predictable equality without implicit conversions.
In front-end apps, memory leaks occur when objects or DOM nodes are unintentionally retained, preventing garbage collection. Chrome DevTools provides tools to find and fix them.
var, let, const, and function declarations. What is the Temporal Dead Zone (TDZ), and why does typeof myVar throw an error for let but not for var?In JavaScript, variables and functions are hoisted differently, which affects their accessibility before the declaration line.
undefined. Accessing them before assignment gives undefined.ReferenceError.let and const exist but cannot be accessed.typeof myVar on a var before declaration returns "undefined". On a let or const, it throws a ReferenceError because the variable is in the TDZ.await in ES Modules, how does it change module execution order, and what problems can it cause when building large applications?Top-level await allows using await directly in ES modules without wrapping code in an async function.
In this example, main.mjs waits for config.mjs to finish its top-level await before running.
import/export), CommonJS (require/module.exports), and dynamic import(). How do import maps and top-level await change the way we structure modern JS apps in 2025?JavaScript has evolved from CommonJS to standardized ES Modules, with newer features improving flexibility and performance.
require/module.exports): Synchronous, designed for Node.js. Modules are loaded at runtime, which blocks execution. Not tree-shakeable by bundlers.import/export): Standardized, static structure. Imports are hoisted and resolved before execution, enabling tree shaking and better optimization. Supported natively in browsers and Node.import(): Asynchronous function that loads modules at runtime. Useful for code-splitting, lazy loading, or conditionally loading features.react → CDN URL). This removes the need for bundlers in some cases and simplifies dependency management in browser-native apps.await: Allows await directly in ES modules without wrapping in async functions. This makes startup code (like fetching config or initializing DB connections) cleaner and reshapes module dependency graphs to support async loading.