JavaScript is a high-level, dynamic, single-threaded interpreted programming language that powers modern interactive web applications. Key foundational concepts include dynamic typing, primitive versus reference data types, automatic type coercion, variable scoping via var, let, and const, and function declarations. Additionally, JavaScript relies on prototype-based inheritance and uses an event-driven, non-blocking execution model managed by an event loop. Mastering core JavaScript syntax, operator precedence, equality comparisons (== vs ===), and standard built-in objects like Arrays and Dictionaries is essential for front-end engineering, back-end Node.js development, and technical technical interview preparation.
Latest JavaScript Basics MCQs
1 min read
Correct Answer: b) clearTimeout()
Explanation:
clearTimeout() takes the timer identifier returned by setTimeout() and cancels its execution.
Correct Answer: b) "function"
Explanation:
In JavaScript, although functions are technically callable objects, typeof returns "function" for them.
Correct Answer: b) &
Explanation:
The single ampersand `&` is used for bitwise AND, whereas `&&` is used for logical AND.
Correct Answer: b) |
Explanation:
The single pipe `|` performs a bitwise OR operation across corresponding bits of its operands.
Correct Answer: a) ^
Explanation:
The caret `^` operator performs a bitwise XOR (exclusive OR) operation on two operands.
Correct Answer: b) ~
Explanation:
The tilde `~` operator inverts all the bits of its operand (bitwise NOT).
Correct Answer: b) 1
Explanation:
The remainder operator `%` returns the remainder left over when one operand is divided by a second operand (10 / 3 = 3 remainder 1).
Correct Answer: b) An environment in which JavaScript code is evaluated and executed
Explanation:
An execution context is an abstract concept that holds information about the environment within which the current code is being executed.
Correct Answer: a) Event Loop
Explanation:
The Event Loop continuously checks if the Call Stack is empty and moves asynchronous callbacks from the Task Queue to the Call Stack.
Correct Answer: b) Microtask Queue
Explanation:
Promise reactions (.then/.catch/await) and MutationObserver callbacks are processed in the Microtask Queue, which takes priority over Macrotasks.
Correct Answer: b) setTimeout() callback
Explanation:
setTimeout, setInterval, and I/O callbacks are categorized as Macrotasks.
Correct Answer: b) "e"
Explanation:
Strings are 0-indexed in JavaScript. Index 0 is 'h' and index 1 is 'e'.
Correct Answer: a) toLowerCase()
Explanation:
toLowerCase() returns the calling string value converted to lower case.
Correct Answer: b) toUpperCase()
Explanation:
toUpperCase() returns the calling string value converted to uppercase.
Correct Answer: a) startsWith()
Explanation:
startsWith() determines whether a string begins with the characters of a specified string, returning true or false.
Correct Answer: a) endsWith()
Explanation:
endsWith() determines whether a string ends with the characters of a specified string.
Correct Answer: b) replace()
Explanation:
replace() returns a new string with one, some, or all matches of a pattern replaced by a replacement.
Correct Answer: a) replaceAll()
Explanation:
replaceAll() returns a new string with all matches of a pattern replaced by a replacement.
Correct Answer: b) ["1", "2", "3"]
Explanation:
Array.from() creates a new array from an iterable object, splitting the string into individual character elements.
Correct Answer: c) length
Explanation:
The `.length` property reflects the number of elements in an array or characters in a string.
Correct Answer: a) Returns an array of an object's enumerable property names
Explanation:
Object.keys() returns an array of a given object's own enumerable property names.
Correct Answer: b) Returns an array of an object's own enumerable string-keyed property values
Explanation:
Object.values() returns an array containing the values of all own enumerable properties of an object.
Correct Answer: c) An array of an object's own enumerable string-keyed property [key, value] pairs
Explanation:
Object.entries() returns an array of a given object's own enumerable string-keyed property [key, value] pairs.
Correct Answer: b) Object.assign()
Explanation:
Object.assign() copies all enumerable own properties from one or more source objects to a target object and returns the target object.
Correct Answer: b) Object.freeze()
Explanation:
Object.freeze() freezes an object: preventing new properties from being added, existing properties from being removed, and existing values from being changed.
Correct Answer: b) Object.seal()
Explanation:
Object.seal() seals an object, preventing new properties from being added and marking existing ones non-configurable, though existing writable values can still be mutated.
Correct Answer: a) Object.isFrozen(obj)
Explanation:
Object.isFrozen() determines if an object is frozen.
Correct Answer: b) Object.prototype
Explanation:
All standard object literals inherit directly from Object.prototype.
Correct Answer: a) Object.create(null)
Explanation:
Object.create(null) creates a clean object with no prototype chain attached.
Correct Answer: a) Object.prototype.hasOwnProperty()
Explanation:
hasOwnProperty() returns a boolean indicating whether the object has the specified property as its own property.
Correct Answer: a) Object.hasOwn(obj, prop)
Explanation:
Object.hasOwn() is a static method introduced to replace hasOwnProperty() for safer property checking on objects created without prototype.
Correct Answer: b) The window object
Explanation:
In non-strict mode, `this` defaults to the global object (`window` in browser context).
Correct Answer: b) undefined
Explanation:
In strict mode, default binding for `this` inside functions is set to `undefined`.
Correct Answer: b) apply()
Explanation:
apply() calls a function with a given `this` value, and arguments provided as an array (or an array-like object).
Correct Answer: b) call()
Explanation:
call() invokes a function with a given `this` value and arguments provided individually.
Correct Answer: b) A new copy of the function with bound `this` and initial parameters
Explanation:
bind() creates a new bound function that wraps the original function object.
Correct Answer: b) Immediately Invoked Function Expression
Explanation:
An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.
Correct Answer: a) (function() {})();
Explanation:
Grouping parentheses `()` wrap the function declaration turning it into an expression, followed by `()` to invoke it immediately.
Correct Answer: b) To create a private scope and avoid polluting the global namespace
Explanation:
IIFEs isolate variable declarations inside their block scope, preventing global scope pollution.
Correct Answer: b) instanceof
Explanation:
The instanceof operator tests whether the prototype property of a constructor appears anywhere along the prototype chain of an object.
Correct Answer: a) true
Explanation:
Array literal `[]` inherits directly from `Array.prototype`, so `[] instanceof Array` evaluates to true.
Correct Answer: a) true
Explanation:
Because `Array.prototype` inherits from `Object.prototype`, arrays are also instances of Object.
Correct Answer: c) globalThis
Explanation:
globalThis provides a standard way to access the global scope across browsers, Node.js, and web workers.
Correct Answer: a) true
Explanation:
In JavaScript, `typeof NaN` returns the string "number", making the expression true.
Correct Answer: b) false
Explanation:
NaN is the only value in JavaScript that is not equal to itself; `NaN === NaN` is false.
Correct Answer: b) Number.isNaN()
Explanation:
Number.isNaN() checks whether the passed value is NaN and its type is Number, avoiding automatic string-to-number coercion of global isNaN().
Correct Answer: b) false
Explanation:
Object.is() treats -0 and +0 as distinct values, returning false.
Correct Answer: b) true
Explanation:
Unlike strict equality (===), Object.is(NaN, NaN) evaluates to true.
Correct Answer: b) A function that can be paused and resumed, returning an Iterator
Explanation:
Generator functions are declared with `function*` and yield values sequentially using the `yield` keyword.
Correct Answer: c) yield
Explanation:
The yield keyword pauses generator function execution and returns the value of the expression following the keyword.
Correct Answer: b) next()
Explanation:
Calling `.next()` resumes generator execution until the next `yield` or `return` statement.
Correct Answer: a) { value: any, done: boolean }
Explanation:
The Iterator protocol dictates that .next() returns an object containing `value` and a boolean `done` property.
Correct Answer: a) Symbol.iterator
Explanation:
The well-known symbol Symbol.iterator specifies the default iterator for an object used by `for...of` loops.
Correct Answer: b) for...in
Explanation:
The `for...in` statement iterates over all enumerable string properties of an object (including inherited ones).
Correct Answer: b) for...of
Explanation:
The `for...of` statement creates a loop iterating over iterable objects, invoking custom iteration hooks with values.
Correct Answer: b) "0", "1"
Explanation:
for...in iterates over array indices (keys), which are string numbers "0" and "1".
Correct Answer: a) 10, 20
Explanation:
for...of iterates over values directly, producing 10 and then 20.
Correct Answer: a) A Map where keys must be objects and are held weakly (garbage collectable)
Explanation:
A WeakMap is a collection of key/value pairs in which the keys MUST be objects and are held as weak references.
Correct Answer: b) No, WeakMaps are non-enumerable and cannot be iterated
Explanation:
Because keys are weakly held, there is no list of keys maintained, making iteration impossible.
Correct Answer: b) A Set that stores weakly held objects
Explanation:
WeakSet objects are collections of garbage-collectable objects where each object may occur only once.
Correct Answer: b) Garbage Collector
Explanation:
JavaScript engines use automatic Garbage Collection (primarily Mark-and-Sweep) to reclaim allocated memory.
Correct Answer: b) When allocated memory is no longer needed by application but is not freed by garbage collector
Explanation:
A memory leak occurs when pieces of memory assigned to variables/objects are retained unnecessarily.
Correct Answer: a) true
Explanation:
The loose equality operator coercively converts `true` to number `1` during comparison.
Correct Answer: b) false
Explanation:
`true` coerces to 1, so `2 == 1` evaluates to false.
Correct Answer: b) Immediately rejects with the reason of the first rejected promise
Explanation:
Promise.all() fails fast: if any passed promise rejects, it immediately rejects with that error.
Correct Answer: a) Promise.race()
Explanation:
Promise.race() resolves or rejects as soon as one of the promises in an iterable resolves or rejects.
Correct Answer: b) Promise.any()
Explanation:
Promise.any() takes an iterable of promises and returns a single promise that resolves as soon as any of the promises fulfills.
Correct Answer: b) Promise.allSettled()
Explanation:
Promise.allSettled() returns a promise that resolves after all of the given promises have either fulfilled or rejected.
Correct Answer: b) TypeError
Explanation:
TypeError represents an error when a value is not of the expected type or operation is inappropriate.
Correct Answer: a) ReferenceError
Explanation:
ReferenceError is thrown when attempting to reference a variable that has not been declared.
Correct Answer: a) SyntaxError
Explanation:
SyntaxError is thrown when trying to interpret syntactically invalid code.
Correct Answer: a) RangeError
Explanation:
RangeError indicates an error when a value is not in the set or range of allowed values (e.g., `new Array(-1)`).
Correct Answer: b) A Promise resolving to the module object
Explanation:
Dynamic import syntax `import()` loads modules asynchronously and returns a Promise.
Correct Answer: a) export
Explanation:
The `export` statement is used when creating JavaScript modules to export functions, objects, or primitive values.
Correct Answer: b) import
Explanation:
The `import` static statement is used to import read-only live bindings exported by another module.
Correct Answer: b) CommonJS (CJS)
Explanation:
CommonJS is the module standard historically used in Node.js relying on `require` and `module.exports`.
Correct Answer: b) fetch()
Explanation:
The Fetch API is a modern, native browser interface for fetching resources asynchronously using Promises.
Correct Answer: b) A Promise resolving to a Response object
Explanation:
fetch() returns a Promise that resolves to the Response object representing the response to the request.
Correct Answer: a) res.json()
Explanation:
The `.json()` method on the Response interface reads the response stream to completion and returns a Promise resolving to JSON data.
Correct Answer: b) localStorage
Explanation:
localStorage data persists even when the browser window/tab is closed and reopened.
Correct Answer: b) sessionStorage
Explanation:
sessionStorage maintains a separate storage area for each given origin that is available for the duration of the page session.
Correct Answer: b) Keys and values must be strings
Explanation:
localStorage stores key-value pairs strictly as UTF-16 strings; objects must be stringified with JSON.stringify().
Correct Answer: b) localStorage.clear()
Explanation:
localStorage.clear() removes all key/value pairs stored for that origin domain.
Correct Answer: a) Web Workers
Explanation:
Web Workers allow background tasks to run on separate threads off the main UI rendering thread.
Correct Answer: b) No, they have no access to the `document` or DOM directly
Explanation:
Web Workers run in a different global context and do not have access to DOM objects like `document`.
Correct Answer: b) postMessage()
Explanation:
The postMessage() method sends messages between the worker thread and main thread.
Correct Answer: a) To add or modify a property on an object with precise descriptors (configurable, writable, enumerable)
Explanation:
Object.defineProperty() defines a new property directly on an object or modifies an existing one, controlling property behavior.
Correct Answer: b) not writable, not enumerable, and not configurable
Explanation:
When using Object.defineProperty(), property descriptors default to false unless explicitly specified true.
Correct Answer: a) Proxy
Explanation:
The Proxy object enables you to create a wrapper for another object, which can intercept and redefine fundamental operations for that object.
Correct Answer: b) Handler
Explanation:
A Proxy is instantiated using `new Proxy(target, handler)`, where `handler` holds trap methods like `get` and `set`.
Correct Answer: a) Reflect
Explanation:
Reflect is a built-in object that provides methods for interceptable JavaScript operations corresponding to Proxy traps.
Correct Answer: b) "bigint"
Explanation:
BigInt is a primitive data type introduced to represent integers larger than 2^53 - 1.
Correct Answer: b) 123n
Explanation:
A BigInt literal is created by appending `n` to the end of an integer.
Correct Answer: b) No, it throws a TypeError
Explanation:
You cannot mix BigInt and regular Number types in operations; explicit conversion is required.
Correct Answer: c) ??=
Explanation:
The logical nullish assignment operator `??=` only assigns if the target evaluates to null or undefined.
Correct Answer: b) 10
Explanation:
Logical OR assignment `||=` assigns when the target is falsy; `0` is falsy, so `x` becomes 10.
Correct Answer: a) 0
Explanation:
Nullish assignment `??=` only assigns if target is null/undefined; `0` is neither, so `x` remains 0.
Correct Answer: b) structuredClone()
Explanation:
structuredClone() creates a deep clone of a given value using the structured clone algorithm.
Correct Answer: c) Throws a SyntaxError
Explanation:
If the string to parse is not valid JSON, JSON.parse() throws a SyntaxError.
Correct Answer: a) flat()
Explanation:
The flat(depth) method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
Correct Answer: b) [1, 2, 3]
Explanation:
Specifying depth 2 flattens nested arrays two levels deep, resulting in a single flat array `[1, 2, 3]`.
Correct Answer: b) flatMap()
Explanation:
flatMap() applies a function to each element and flattens the result by one level.
Related Posts

Python OOP MCQs
Object-Oriented Programming (OOP) in Python is a programming paradigm that uses classes and objects to model real world entities, promoting…
August 27, 2026By MCQs Generator

Latest Java Arrays MCQs
In Java, an array is a dynamically allocated object used to store a fixed-size sequential collection of elements of the…
October 19, 2026By MCQs Generator

Python Modules & Packages MCQs
Python modules are single files containing Python code (functions, classes, and variables) that can be imported and reused across different…
October 19, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator