Top 30 Javascript Interview Questions and Answers
30 multiple-choice questions on Javascript, drawn from 30 bites out of the 161 tagged Javascript on Tezvyn. Answer them here or read straight down. Every question carries the correct option, why it is correct, and a link to the bite it came from.
30 questions. Pick an answer, or open “Show the answer” to read it.
Answers are graded in your browser. Nothing is saved, and no XP or streak is earned here. The app keeps score.
Question 1 of 30
What is the primary advantage of Vue's progressive philosophy for a project starting small but potentially growing into a full SPA?
Show the answer
Answer: b · It enables developers to integrate only the necessary parts of its ecosystem, scaling functionality as needed.
The progressive philosophy allows Vue to be adopted incrementally, starting with its core library for small enhancements and gradually integrating more of its ecosystem as the project's complexity grows. Option A is incorrect because Vue is designed to be less opinionated, offering flexibility rather than strict guidance from the outset.
Read the full bite: Vue: The Progressive Framework Philosophy
Question 2 of 30
What is the primary function of the V8 engine within environments like Chrome or Node.js?
Show the answer
Answer: c · To translate JavaScript code into native machine code for fast execution.
V8's core role is to compile JavaScript into native machine code, enabling high-performance execution. While environments like Node.js provide APIs for interactions (option D), V8 itself is solely the engine responsible for processing the JavaScript code.
Read the full bite: V8: The Engine Powering Chrome and Node.js
Question 3 of 30
How does Turbopack's Server Fast Refresh in Next.js 16.2 differ from the previous server-side reload behavior?
Show the answer
Answer: c · It reloads only the changed module and leaves the rest of the server process intact, rather than clearing the require.cache for the entire import chain.
Turbopack now surgically reloads only the changed module while leaving the server process intact, replacing the old behavior of clearing require.cache for the changed file and its entire import chain. Option A is tempting because it mentions require.cache and node_modules, but the old system actually cleared untouched node_modules in the import chain, and the new approach avoids chain-wide cache clearing entirely.
Read the full bite: Next.js 16.2 brings 67-100% faster server Fast Refresh
Question 4 of 30
Which change to Vue's template parser in 3.4 is primarily responsible for its 2× speed improvement?
Show the answer
Answer: b · It replaced recursive descent and heavy regex with a single-pass state-machine tokenizer
The card states the parser was rewritten from a recursive descent approach relying on heavy regex to a state-machine tokenizer based on htmlparser2 that iterates only once. Option A is tempting because it mentions htmlparser2, but the old regex-based tokenizer was fully replaced, not retained.
Read the full bite: Vue 3.4 Cuts Build Times 44%, Stabilizes defineModel
Question 5 of 30
For which file is //# allFunctionsCalledOnLoad the most appropriate optimization?
Show the answer
Answer: c · A core entry-point bundle whose functions execute during initial page load
The hint is designed for known startup files so V8 can compile them in the background during network load. Using it on all scripts (A) or on non-startup files (A, D) wastes CPU and memory without improving startup time.
Read the full bite: Chrome 136 cuts JS startup 630ms with compile hints
Question 6 of 30
What condition forces V8's JSON.stringify to abandon its new side-effect-free fast path and use the slower recursive serializer?
Show the answer
Answer: a · One of the properties defines a custom toJSON method
Custom toJSON methods execute user code during serialization, violating the side-effect-free guarantee required for the fast path. Deep nesting is actually improved by the iterative fast path, while Unicode strings and null-prototype objects do not inherently trigger the slower recursive serializer.
Read the full bite: V8 doubles JSON.stringify speed with side-effect-free fast path
Question 7 of 30
What is the fundamental nature of a React Component?
Show the answer
Answer: d · A JavaScript function that returns a description of UI using JSX.
The card explicitly states, "A React component is a JavaScript function that returns a piece of UI" and that it returns "JSX" to describe the UI. While components are analogous to custom HTML tags, their core implementation is a JavaScript function.
Read the full bite: React Components: Your UI Building Blocks
Question 8 of 30
How did SvelteKit 2.61 change the argument passed to an enhance callback?
Show the answer
Answer: d · It now receives a copy of the form remote function instance with a submit() API
The card states that enhance callbacks now receive a copy of the form remote function instance exposing its own submit() API, replacing the old destructured object. Option B is tempting because it mixes the old callback shape with the new live() query feature, but live() is unrelated to enhance arguments.
Read the full bite: SvelteKit 2.61 breaks remote functions, adds live queries
Question 9 of 30
When using Vue 3.5's stable reactive props destructure, what must you do to keep a destructured prop reactive when passing it to watch or a composable?
Show the answer
Answer: d · Wrap the variable in a getter function
Vue 3.5 requires wrapping destructured props in getters when passing them to watch or composables to preserve reactivity. Passing them directly severs the reactive link, and withDefaults is the old boilerplate this feature replaces.
Read the full bite: Vue 3.5 cuts reactivity memory 56%, adds lazy hydration
Question 10 of 30
What is the fundamental nature of JSX in a React application?
Show the answer
Answer: d · It is a syntax extension that a build tool converts into standard JavaScript function calls.
The card explains that JSX is a "syntax extension" that "gets compiled into plain JavaScript objects" by a "compiler (like Babel)" into "React.createElement() function calls." Option C is incorrect because the card explicitly states JSX is "not a string, nor is it HTML."
Read the full bite: JSX: Putting HTML Inside Your JavaScript Components
Question 11 of 30
When would a TypeScript tuple be the most appropriate choice compared to an array?
Show the answer
Answer: d · To represent a single point in 2D space, like [x-coordinate, y-coordinate].
A tuple is ideal for fixed-length structures where the position and type of each element are important, such as a coordinate pair. An array is used for variable-length lists of elements of the same type, making options A, C, and D incorrect.
Read the full bite: TypeScript's Basic Types: The Building Blocks
Question 12 of 30
What is the primary benefit of Svelte's architecture as a compiler, rather than a traditional runtime framework?
Show the answer
Answer: a · It generates highly optimized, vanilla JavaScript during the build process, eliminating the need for a runtime library in the browser.
The card emphasizes that Svelte shifts work from runtime to compile time, generating efficient vanilla JavaScript and avoiding a large runtime library, which leads to smaller bundles and improved performance. While Svelte does offer a declarative syntax (option C), this is a feature of many frameworks and not the primary benefit of its *compiler* architecture.
Read the full bite: Svelte: A Compiler, Not Just a Framework
Question 13 of 30
Which statement accurately describes a core principle of how React components should handle props?
Show the answer
Answer: b · Props facilitate a one-way data flow, allowing data to be passed from parent to child components.
The card states that props establish a 'clear, one-way data flow from parent components to child components.' This ensures predictability and reusability. Option A is incorrect because a component should never modify the props it receives; that's what state is for.
Read the full bite: React Props: Arguments for Your Components
Question 14 of 30
Which statement accurately describes Metro's primary role in a React Native project?
Show the answer
Answer: c · It compiles multiple JavaScript source files into a single, optimized bundle for execution.
Metro's core function is to act as a "specialized compiler" that takes numerous JavaScript files, resolves dependencies, transforms code, and combines them into a single, optimized bundle for efficient loading on devices. Option B describes a package manager, C describes native build tools, and D describes the React Native framework itself.
Read the full bite: Metro: The JavaScript Bundler for React Native
Question 15 of 30
What is the primary issue with using `onClick={myFunction()}` instead of `onClick={myFunction}` in a React component?
Show the answer
Answer: c · It executes `myFunction` immediately during the component's render phase, not when the user clicks.
The card explicitly states that `onClick={handleClick()}` is incorrect because "The parentheses () execute the function immediately during the component's render phase." This means the function runs when the component is drawn, not when the user interacts with it. Option D is incorrect because it's a logical error, not a syntax error.
Question 16 of 30
What is the fundamental mechanism by which Hermes improves React Native app startup performance?
Show the answer
Answer: d · It performs Ahead-Of-Time (AOT) compilation of JavaScript into optimized bytecode during the app's build phase.
Hermes is an Ahead-Of-Time (AOT) focused engine that pre-compiles JavaScript into optimized bytecode during the build process, reducing the work the device has to do at startup. While it contributes to a smaller app size, its primary mechanism for faster startup is not tree-shaking or JIT compilation.
Read the full bite: Hermes: The JS Engine for Faster React Native Apps
Question 17 of 30
Which approach best implements click tracking for dozens of headlines and CTAs while remaining performant and maintainable?
Show the answer
Answer: b · Use a single delegated listener on a parent container, read data attributes to identify elements, and send via navigator.sendBeacon
Event delegation on a common ancestor avoids the performance cost of dozens of individual listeners and naturally handles dynamic content, while data attributes provide stable identifiers unlike brittle innerText or class names. The most tempting distractor, attaching unique listeners to every element, scales poorly and misses the efficiency and dynamic-content benefits that delegation provides.
Read the full bite: How would you track clicks on headlines and calls-to-action?
Question 18 of 30
When using the logical AND operator (condition && <Component />) for conditional rendering in React, what is a crucial behavior to be aware of?
Show the answer
Answer: d · If 'condition' evaluates to 0, the number 0 might be displayed in the UI.
The card explicitly mentions this as a 'footgun': if 'condition' is the number 0, the expression '0 && <Component />' evaluates to 0, which React will render. Option C is incorrect because JavaScript's logical AND operator works with any truthy or falsy value, not just strict booleans.
Read the full bite: Conditional Rendering: Show UI Based on State
Question 19 of 30
When developing a complex Vue component with intertwined logic for a single feature (e.g., data fetching and its related states), which API is generally preferred and why?
Show the answer
Answer: a · Composition API, because it enables grouping all related logic for a feature together, enhancing co-location and reusability.
The Composition API is preferred for complex components because it allows grouping all related logic for a specific feature, like data fetching and its states, in one place, improving co-location and reusability. The Options API, conversely, tends to scatter such related logic across different sections (data, methods, mounted), making complex components harder to manage and debug.
Question 20 of 30
During a normal page navigation in the same browser tab, which object is replaced while the other persists?
Show the answer
Answer: b · Only the document object is replaced; the window object persists as the tab container.
The window object represents the browser tab and global execution context, so it persists across navigation, while the document is the in-memory DOM representation of a specific page and is rebuilt. Claiming both are replaced is a common misconception that treats window and document as the same page-level entity rather than as container versus content.
Read the full bite: What is the fundamental difference between window and document?
Question 21 of 30
How does Vue's reactivity system primarily ensure UI components update automatically with data changes?
Show the answer
Answer: b · It wraps data objects in JavaScript Proxies to intercept property access and modification, triggering updates when changes occur.
Vue's reactivity system uses JavaScript Proxies to wrap data, intercepting 'get' operations to track dependencies and 'set' operations to notify subscribers for updates. Option A describes a polling mechanism, which is not how Vue's event-driven reactivity works.
Read the full bite: Vue's Reactivity: JavaScript That Acts Like a Spreadsheet
Question 22 of 30
In a browser script, what distinguishes a top-level var declaration from let or const?
Show the answer
Answer: b · var creates a property on the global Window object, while let and const do not, though all three are globally scoped
var creates a writable property on the global Window object, while let and const are globally scoped without becoming Window properties. Option A is a tempting misconception because let and const are indeed globally scoped; they simply do not pollute the global object.
Read the full bite: What happens when you declare var globally versus let or const?
Question 23 of 30
According to the CommonJS mental model, what is the default state of variables and functions defined within a module file?
Show the answer
Answer: b · They are private to the module unless explicitly exported.
The card states, "By default, all tools and materials (variables, functions) inside are private. To share a tool, you place it on a public shelf called exports." This means they are private unless explicitly exported. Options A and B describe the opposite of CommonJS's encapsulation, and D is incorrect because variables are accessible within their own module before any import.
Read the full bite: CommonJS: Node.js's Original Module System
Question 24 of 30
What is the main reason vite.config.js is designed as a Node.js script capable of exporting a function?
Show the answer
Answer: b · To enable programmatic configuration adjustments based on the current command or environment mode.
The card emphasizes that vite.config.js is a dynamic script allowing conditional logic based on context like 'command' or 'mode', which is the core purpose of exporting a function. While defineConfig (Option C) is a benefit, it's not the primary reason for the dynamic script design itself.
Read the full bite: Vite Config: The Control Panel for Your Build
Question 25 of 30
What is the main drawback of adding your own variables and functions directly to the window object?
Show the answer
Answer: b · It increases the risk of naming conflicts and makes your code fragile.
The card states that adding variables directly to the window object "makes your code fragile and can lead to conflicts with third-party scripts." This 'global scope pollution' is the primary concern, not memory, security, or module prevention.
Read the full bite: The `window` Object: Your Browser's Global Scope
Question 26 of 30
Which statement about a Promise's state transitions is correct?
Show the answer
Answer: a · Once settled as fulfilled or rejected, the state is permanent and cannot change
Settling is one-way and final; a Promise transitions from pending to exactly one of fulfilled or rejected and stays there. then callbacks run later as microtasks, not synchronously.
Read the full bite: The three states of a JavaScript Promise
Question 27 of 30
You add a click listener to a parent with addEventListener('click', fn, true). When does fn run relative to a child element's default listener if the child is clicked?
Show the answer
Answer: c · fn runs before the child listener during event capture
Passing true as the third argument registers the parent listener for the capture phase, which fires as the event travels downward from the root, so it executes before the child's bubble-phase listener. Option B describes the default behavior when the third argument is omitted or false, not capture.
Read the full bite: Explain DOM event capturing and bubbling with addEventListener
Question 28 of 30
Why does the Promise callback print before the setTimeout(0) callback despite both being scheduled in the same tick?
Show the answer
Answer: d · The microtask queue is fully drained before the next macrotask runs
After the synchronous stack clears, all microtasks (Promise reactions) drain before any macrotask (setTimeout) runs. The delay value is not the deciding factor here; queue priority is.
Read the full bite: Output order of sync, microtask, and macrotask
Question 29 of 30
After storing parent.childNodes in a variable, a developer appends a new child and sees the stored length increase without reassignment. What explains this?
Show the answer
Answer: d · The stored reference is a live NodeList, but querySelectorAll returns a static snapshot that would not update.
childNodes is a live NodeList that mutates in place, while querySelectorAll returns a static snapshot that never updates. A is tempting because many developers assume all NodeLists share the same binding behavior, but querySelectorAll specifically captures a point-in-time copy.
Read the full bite: What are the key differences between NodeList and HTMLCollection?
Question 30 of 30
Which task is NOT primarily handled by the `document` object in JavaScript?
Show the answer
Answer: d · Redirecting the browser to a different web address.
The `document` object is for interacting with the page's content and structure, such as modifying elements, creating new ones, or finding existing elements. Navigating to a new URL is a browser-level action handled by the `window.location` object, not the `document` object.
Could you explain these out loud?
That is what an interview actually tests. Tezvyn gives you questions like these with what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.