What is JavaScript, and how is it related to ECMAScript?
Topic: Language basics and types
JavaScript is a programming language; ECMAScript is the standard defining its core behavior.
180 common interview questions in English. Fundamentals, closures, objects, async code, browser APIs, testing, and coding exercises. Short answers for further study.
0 із 180 карток позначено «Знаю» у цьому демо.
Answer aloud, then check the short answer. Search by question or topic.
Topic: Language basics and types
JavaScript is a programming language; ECMAScript is the standard defining its core behavior.
Topic: Language basics and types
They are separate languages. Similar names do not imply the same type system, runtime, or object model.
Topic: Language basics and types
Undefined, null, boolean, number, bigint, string, and symbol.
Topic: Language basics and types
Primitives are immutable values. Objects have identity and can contain mutable properties.
Topic: Language basics and types
Values have types; a variable can hold values of different types over time.
Topic: Language basics and types
Null usually expresses intentional absence; undefined commonly means a value has not been provided.
Topic: Language basics and types
Use typeof for most primitives, Array.isArray for arrays, and value === null for null.
Topic: Language basics and types
It is a historical language quirk. Null is still a primitive.
Topic: Language basics and types
NaN represents an invalid numeric result. Number.isNaN(value) checks without coercion.
Topic: Language basics and types
Number.isNaN checks the value directly; global isNaN converts it to a number first.
Topic: Language basics and types
Falsy: false, 0, -0, 0n, empty string, null, undefined, NaN; also legacy document.all in browsers. Other values are truthy.
Topic: Language basics and types
Yes. Their emptiness does not affect their boolean conversion.
Topic: Language basics and types
A unique primitive often used as a property key or to customize built-in protocols.
Topic: Language basics and types
For integers beyond Number's safe range. Most arithmetic cannot mix BigInt and Number directly.
Topic: Language basics and types
Binary floating-point cannot represent these decimals exactly. Compare using a tolerance appropriate to the calculation.
Topic: Variables, scope, and operators
Var is function- or global-scoped; let and const are block-scoped. Const prevents reassignment.
Topic: Variables, scope, and operators
No. It prevents rebinding the variable; the object's properties may still change.
Topic: Variables, scope, and operators
They determine where a binding is accessible: globally, within a function, or within a block.
Topic: Variables, scope, and operators
A function's access to outer bindings depends on where it is defined in the source.
Topic: Variables, scope, and operators
Declarations affect bindings before their source line runs; initialization rules differ by declaration type.
Topic: Variables, scope, and operators
The period from entering a scope until a let, const, or class binding is initialized; accessing it throws.
Topic: Variables, scope, and operators
An inner binding uses the same name as an outer binding, hiding it within that scope.
Topic: Variables, scope, and operators
== may convert types; === compares without type coercion. Objects are compared by identity.
Topic: Variables, scope, and operators
Object.is treats NaN as equal to itself and distinguishes +0 from -0.
Topic: Variables, scope, and operators
JavaScript automatically converts a value for an operation, such as converting a number during string concatenation.
Topic: Variables, scope, and operators
|| falls back for any falsy value; ?? falls back only for null or undefined.
Topic: Variables, scope, and operators
?. returns undefined if the value being accessed is null or undefined, instead of continuing that access.
Topic: Variables, scope, and operators
&&, ||, and ?? evaluate the right operand only when needed and return an operand value.
Topic: Variables, scope, and operators
Rest collects remaining values; spread expands an iterable or copies an object's own enumerable properties.
Topic: Variables, scope, and operators
Destructuring extracts values into bindings; template literals support interpolation and multiline strings.
Topic: Functions and closures
A declaration initializes its function before execution in its scope; an expression creates a function when evaluated.
Topic: Functions and closures
Arrows capture surrounding this and arguments, cannot be constructors, and have no own prototype property.
Topic: Functions and closures
They can be assigned, passed as arguments, and returned from other functions.
Topic: Functions and closures
A function that accepts functions, returns a function, or both.
Topic: Functions and closures
A function passed to another operation to be invoked; callbacks can be synchronous or asynchronous.
Topic: Functions and closures
A function together with access to its surrounding lexical bindings, even after the outer function returns.
Topic: Functions and closures
For private state, configured callbacks, function factories, and remembering values between calls.
Topic: Functions and closures
Callbacks share one var binding. Let creates a separate binding for each loop iteration.
Topic: Functions and closures
A function expression called immediately, often to create a private scope.
Topic: Functions and closures
A function whose result depends only on its inputs and that causes no observable side effects.
Topic: Functions and closures
An observable change outside a function's returned value, such as mutation, logging, or a network request.
Topic: Functions and closures
Transforming a function with multiple arguments into a sequence of functions taking one argument each.
Topic: Functions and closures
Currying changes the calling structure; partial application fixes some arguments to produce a new function.
Topic: Functions and closures
Caching results by input to avoid repeated work; consider cache size and changing dependencies.
Topic: Functions and closures
A function calls itself on a smaller problem. Missing termination or excessive depth can overflow the stack.
Topic: This, prototypes, and classes
By how it is called: as a method, constructor, explicit binding, or plain call.
Topic: This, prototypes, and classes
Undefined, unless the function is bound; arrow functions instead capture their surrounding this.
Topic: This, prototypes, and classes
The original receiver is lost unless the caller supplies it; bind it or wrap the call.
Topic: This, prototypes, and classes
Call and apply invoke with a chosen this; apply takes array-like arguments. Bind returns a bound function.
Topic: This, prototypes, and classes
Creates an object, links its prototype, and calls the constructor with that this; an explicit object return can replace it.
Topic: This, prototypes, and classes
Property lookup checks an object, then successive prototypes, until a match or null.
Topic: This, prototypes, and classes
The constructor's .prototype usually becomes the internal prototype of instances created with new.
Topic: This, prototypes, and classes
Use Object.create(proto); Object.create(null) creates an object without a prototype.
Topic: This, prototypes, and classes
Classes provide syntax and rules over prototype-based inheritance; instance methods normally live on the prototype.
Topic: This, prototypes, and classes
Extends establishes inheritance; super accesses parent behavior and calls the parent constructor in a derived constructor.
Topic: This, prototypes, and classes
Instance methods are called on instances; static methods are called on the class itself.
Topic: This, prototypes, and classes
Fields beginning with # are only accessible from permitted code inside the declaring class.
Topic: This, prototypes, and classes
Accessor functions that run when a property is read or assigned.
Topic: This, prototypes, and classes
Normally, whether a constructor's prototype appears in the object's prototype chain; cross-realm checks can surprise you.
Topic: This, prototypes, and classes
When behavior is easier to combine through smaller objects or functions than a rigid class hierarchy.
Topic: Objects and copying
Arguments are passed by value. An object value is a reference: mutation is shared, parameter reassignment is not.
Topic: Objects and copying
A shallow copy shares nested objects; a deep copy recreates supported nested data.
Topic: Objects and copying
Use { ...object } or Object.assign({}, object); nested values remain shared.
Topic: Objects and copying
To deeply clone supported data, including cycles, Maps, and Dates; functions and DOM nodes are not supported.
Topic: Objects and copying
It loses unsupported values and types, fails on cycles, and normally throws on BigInt.
Topic: Objects and copying
Use Object.hasOwn(object, key); the in operator also checks inherited properties.
Topic: Objects and copying
Arrays of own enumerable string-keyed property names, values, or key-value pairs.
Topic: Objects and copying
Use Object.fromEntries(iterableOfPairs).
Topic: Objects and copying
Dot uses a fixed identifier; brackets accept an expression, including dynamic strings and symbols.
Topic: Objects and copying
Use delete object.key; assigning undefined keeps the property present.
Topic: Objects and copying
Both prevent adding or removing properties; freeze also makes data properties nonwritable. Both are shallow.
Topic: Objects and copying
Metadata controlling writability, enumerability, configurability, or getter/setter behavior.
Topic: Objects and copying
=== checks identity. Comparing contents requires a definition of equality and a suitable comparison function.
Topic: Objects and copying
JSON is a text data format with limited types; objects are runtime values that can contain behavior.
Topic: Objects and copying
Proxy intercepts object operations; Reflect provides functions for performing many of those operations.
Topic: Arrays, strings, and collections
Map transforms into a new array; forEach visits elements and returns undefined; filter selects matching elements.
Topic: Arrays, strings, and collections
Combines elements into an accumulator. An explicit initial value handles empty arrays safely.
Topic: Arrays, strings, and collections
Find returns the first match; findIndex its index; some checks any match; every checks all.
Topic: Arrays, strings, and collections
Slice copies a range; splice changes the original array by removing, replacing, or inserting elements.
Topic: Arrays, strings, and collections
Push, pop, shift, unshift, splice, sort, reverse, fill, and copyWithin.
Topic: Arrays, strings, and collections
Use numbers.sort((a, b) => a - b); default sorting compares string representations.
Topic: Arrays, strings, and collections
Use toSorted()/toReversed(), or copy first and then sort/reverse.
Topic: Arrays, strings, and collections
For...in visits enumerable string property keys, including inherited ones; for...of consumes iterable values.
Topic: Arrays, strings, and collections
Map accepts arbitrary keys, exposes size, and is directly iterable; object property keys are strings or symbols.
Topic: Arrays, strings, and collections
Storing unique values and checking membership; distinct objects remain distinct even with identical contents.
Topic: Arrays, strings, and collections
Weak collections do not keep their weakly held keys/values alive and cannot be enumerated.
Topic: Arrays, strings, and collections
Iterables provide an iterator; iterators return next results; generators use function* and yield to produce them.
Topic: Arrays, strings, and collections
No. String operations return new values; indexed assignment does not change a string.
Topic: Arrays, strings, and collections
Split turns a string into an array; join combines array elements; trim removes surrounding whitespace.
Topic: Arrays, strings, and collections
They describe text patterns. Use regex.test(text) for a boolean; match or exec for match details.
Topic: Promises and async functions
Synchronous steps finish in sequence; asynchronous operations allow a result to be handled later.
Topic: Promises and async functions
It represents an eventual outcome: pending, fulfilled, or rejected. Settled means fulfilled or rejected.
Topic: Promises and async functions
Yes. The function passed to new Promise runs immediately; .then handlers run asynchronously.
Topic: Promises and async functions
Each .then returns a new promise that adopts the handler's returned value or promise, or rejects if it throws.
Topic: Promises and async functions
Catch handles rejection; finally runs cleanup and normally preserves the outcome unless it throws or returns a rejecting promise.
Topic: Promises and async functions
Always a promise: returned values fulfill it; uncaught throws reject it.
Topic: Promises and async functions
Pauses that async function or module until a value settles; it does not block the whole JavaScript thread.
Topic: Promises and async functions
Use try/catch around awaited operations, or let rejection propagate to a caller that handles it.
Topic: Promises and async functions
Collects results in input order; rejects on the first rejection. It does not cancel the remaining operations.
Topic: Promises and async functions
Waits for all inputs to settle and returns each fulfillment value or rejection reason.
Topic: Promises and async functions
Race follows the first settlement; any follows the first fulfillment and rejects only if all reject.
Topic: Promises and async functions
Start them before awaiting their combined results, often with Promise.all.
Topic: Promises and async functions
ForEach ignores callback return values. Use for...of for sequencing or Promise.all(array.map(...)) for concurrency.
Topic: Promises and async functions
The chain cannot wait for that operation or track its outcome unless you return or otherwise handle it.
Topic: Promises and async functions
For fetch, pass an AbortSignal and call its controller's abort(). Promises themselves have no universal cancellation method.
Topic: Event loop, timers, and errors
One agent runs one piece of JavaScript at a time; hosts and workers can perform other work concurrently.
Topic: Event loop, timers, and errors
The stack of active function calls; a call pushes a frame, and returning removes it.
Topic: Event loop, timers, and errors
Coordinates queued work with JavaScript execution, letting asynchronous callbacks run when execution can proceed.
Topic: Event loop, timers, and errors
Timers and events queue tasks; promise reactions queue microtasks, drained at checkpoints before the next task.
Topic: Event loop, timers, and errors
No. It schedules a later task; current execution and queued microtasks run first.
Topic: Event loop, timers, and errors
No. The delay is a threshold; busy execution and browser throttling can postpone it.
Topic: Event loop, timers, and errors
SetInterval schedules repeatedly; recursive setTimeout can schedule the next run after the previous work completes.
Topic: Event loop, timers, and errors
For visual updates aligned with the browser's rendering cycle; use its timestamp for animation progress.
Topic: Event loop, timers, and errors
It blocks the main thread, delaying input, rendering, and callbacks.
Topic: Event loop, timers, and errors
A separate execution context for background JavaScript; it communicates through messages and cannot directly access the DOM.
Topic: Event loop, timers, and errors
Yes. Continually queueing microtasks can delay tasks and rendering.
Topic: Event loop, timers, and errors
Try runs code, catch handles thrown errors, and finally performs cleanup as control leaves the construct.
Topic: Event loop, timers, and errors
No. The callback runs later; catch inside it or propagate the error through a handled promise.
Topic: Event loop, timers, and errors
Error is general; TypeError signals an invalid type-related operation; ReferenceError signals an invalid binding reference.
Topic: Event loop, timers, and errors
It hides failures and can leave invalid state. Recover explicitly or report and propagate with useful context.
Topic: DOM and browser events
The browser's object representation of a document, which scripts can inspect and change.
Topic: DOM and browser events
QuerySelector returns the first match or null; querySelectorAll returns a static NodeList of matches.
Topic: DOM and browser events
A live collection updates with DOM changes; a static collection preserves its membership from query time.
Topic: DOM and browser events
TextContent handles text; innerText reflects rendered text; innerHTML parses or serializes markup.
Topic: DOM and browser events
Use document.createElement(), set properties, then append or insert it into the document.
Topic: DOM and browser events
Capturing travels toward the target; bubbling travels back through ancestors for events that bubble.
Topic: DOM and browser events
An ancestor handles descendant events, often using closest() to identify the relevant child.
Topic: DOM and browser events
Target identifies the event's target; currentTarget is the element whose listener is currently running.
Topic: DOM and browser events
PreventDefault cancels a cancelable default action; stopPropagation stops travel to other nodes.
Topic: DOM and browser events
It also prevents later listeners for that event on the same element.
Topic: DOM and browser events
Use removeEventListener with the same type, function, and capture value, or abort its registered signal.
Topic: DOM and browser events
It promises not to call preventDefault(), allowing the browser to handle actions such as scrolling without waiting for cancellation.
Topic: DOM and browser events
DOMContentLoaded follows parsing and deferred/module script execution; window load also waits for dependent resources such as images.
Topic: DOM and browser events
Async executes when ready without ordering guarantees; defer executes after parsing in document order, before DOMContentLoaded.
Topic: DOM and browser events
Debouncing groups nearby calls, often waiting for quiet; throttling limits execution frequency over time.
Topic: Requests, storage, and security
Await fetch, check response.ok, then await response.json(); handle request and parsing failures.
Topic: Requests, storage, and security
No. HTTP error responses normally fulfill it; check response.ok or status yourself.
Topic: Requests, storage, and security
Set method to POST, Content-Type to application/json, and body to JSON.stringify(data).
Topic: Requests, storage, and security
A browser protocol where server headers determine whether scripts may read cross-origin responses.
Topic: Requests, storage, and security
It usually produces an opaque response whose body and status JavaScript cannot read.
Topic: Requests, storage, and security
The combination of scheme, hostname, and port.
Topic: Requests, storage, and security
LocalStorage persists; sessionStorage is scoped to a tab's session; matching cookies can be sent automatically with requests.
Topic: Requests, storage, and security
For larger structured data and asynchronous transactions; localStorage is synchronous and stores strings.
Topic: Requests, storage, and security
Untrusted content executes as script in a site's context. Use safe text rendering and appropriate sanitization for allowed HTML.
Topic: Requests, storage, and security
It parses input as markup and can enable XSS. Use textContent for plain text.
Topic: Requests, storage, and security
A malicious site causes unwanted authenticated requests. Mitigations include appropriate SameSite cookies, CSRF tokens, and origin validation.
Topic: Requests, storage, and security
They restrict script access, transport to HTTPS, and cross-site sending, respectively.
Topic: Requests, storage, and security
Users can inspect downloaded code and requests. Keep privileged secrets on a trusted server.
Topic: Requests, storage, and security
Older responses may arrive later and overwrite newer results; cancel stale requests or check a request identifier.
Topic: Requests, storage, and security
Use bounded retries with backoff for suitable operations; avoid blindly repeating non-idempotent actions.
Topic: Modules, performance, and testing
Files with explicit imports and exports, their own scope, and strict-mode behavior.
Topic: Modules, performance, and testing
Named exports are imported by exported name; a default export can be given any local import name.
Topic: Modules, performance, and testing
Static imports declare dependencies upfront; import() loads a module on demand and returns a promise.
Topic: Modules, performance, and testing
ESM uses import/export and live bindings; CommonJS uses require/module.exports and typically loads synchronously.
Topic: Modules, performance, and testing
A transpiler rewrites syntax; a polyfill supplies a missing runtime API.
Topic: Modules, performance, and testing
Bundling combines modules; tree shaking removes unused code; code splitting separates code for selective loading.
Topic: Modules, performance, and testing
It rejects some previously silent mistakes, forbids accidental globals, and changes plain-call this to undefined.
Topic: Modules, performance, and testing
The engine reclaims memory that is no longer reachable; the exact timing is not guaranteed.
Topic: Modules, performance, and testing
Unwanted reachable data, such as retained listeners, timers, detached DOM nodes, or unbounded caches.
Topic: Modules, performance, and testing
Reproduce it, profile the bottleneck, measure a targeted change, and check for regressions.
Topic: Modules, performance, and testing
Repeated DOM writes followed by layout reads can force extra layout; batch reads and writes.
Topic: Modules, performance, and testing
They share the language but expose different host APIs: browsers provide the DOM; Node provides server and filesystem APIs.
Topic: Modules, performance, and testing
Unit tests check small units; integration tests check interactions; end-to-end tests check complete user flows.
Topic: Modules, performance, and testing
Return or await the operation, assert outcomes and failures, and control timers or external dependencies when needed.
Topic: Modules, performance, and testing
Reproduce it, reduce the case, inspect state and stack traces, test a hypothesis, and verify the fix.
Topic: Common coding exercises and output questions
Use [...new Set(values)]; decide separately how object duplicates should be identified.
Topic: Common coding exercises and output questions
Accumulate counts in a Map, incrementing the count for each value.
Topic: Common coding exercises and output questions
Define normalization rules, then compare characters from both ends or compare with a reversed copy.
Topic: Common coding exercises and output questions
Normalize as required and compare character frequencies, or sort and compare their characters.
Topic: Common coding exercises and output questions
Use flat(depth), or recursively visit nested arrays. Choose whether all nesting should be flattened.
Topic: Common coding exercises and output questions
Keep a timer in a closure; clear it on each call, then schedule the callback with the latest arguments and receiver.
Topic: Common coding exercises and output questions
Track the last execution or a pending timer; define whether leading and trailing calls should run.
Topic: Common coding exercises and output questions
Return a function that closes over a local count and increments it on each call.
Topic: Common coding exercises and output questions
Accumulate arrays in a Map keyed by that property; append each object to its group.
Topic: Common coding exercises and output questions
'52' and 3. Addition concatenates when a string operand is involved; subtraction converts to numbers.
Topic: Common coding exercises and output questions
false, false. The arrays have different identities; NaN is not strictly equal to itself.
Topic: Common coding exercises and output questions
2. Both variables refer to the same object.
Topic: Common coding exercises and output questions
undefined. The var binding exists before its initializer runs.
Topic: Common coding exercises and output questions
A ReferenceError: x is accessed during its temporal dead zone.
Topic: Common coding exercises and output questions
A, D, C, B: synchronous logs, then the promise microtask, then the timer task.