Functions are the primary building blocks of JavaScript applications, enabling code modularity, encapsulation, and reuse. In JavaScript, functions are first-class citizens, meaning they can be assigned to variables, passed as arguments to other functions, and returned from function calls. Modern ECMAScript specifications (ES6+) expanded functional syntax beyond traditional declarations and expressions to include arrow functions (() => {}), default parameter values, and rest parameter syntax (...args). Mastering execution contexts, lexical scoping, closures, hoisting behavior, and explicit binding methods (call, apply, bind) is critical for writing predictable asynchronous or synchronous code and succeeding in technical interviews.
JavaScript Functions MCQs
1 min read
Correct Answer: a) Hello
Explanation:
Function declarations are fully hoisted to the top of their containing scope, allowing them to be invoked prior to their definition line.
Correct Answer: b) TypeError: bar is not a function
Explanation:
The variable declaration 'var bar' is hoisted as undefined. Attempting to invoke undefined as a function raises a TypeError.
Correct Answer: b) It takes one or more functions as arguments or returns a function.
Explanation:
A higher-order function is any function that operates on other functions by accepting them as parameters, returning them, or both.
Correct Answer: a) 10
Explanation:
The rest parameter ...numbers captures all arguments as an array [1, 2, 3, 4], which reduce then sums to 10.
Correct Answer: c) 10
Explanation:
Default parameters can reference preceding parameters. Here 'b' defaults to 'a' (5), so 5 + 5 evaluates to 10.
Correct Answer: c) ReferenceError: Cannot access 'y' before initialization
Explanation:
Default parameters are evaluated left-to-right in their temporal dead zone. Accessing 'y' before its initialization line throws a ReferenceError.
Correct Answer: b) undefined
Explanation:
When unbound() is invoked without an explicit receiver object, its 'this' defaults to global (or undefined in strict mode), missing 'num'.
Correct Answer: a) const bound = unbound.bind(obj);
Explanation:
Function.prototype.bind creates a new bound function that locks its 'this' binding to the provided target object.
Correct Answer: b) Arguments must be passed as a single array or array-like object.
Explanation:
apply() invokes a function immediately, taking 'this' as its first parameter and an array of arguments as its second parameter.
Correct Answer: c) 2
Explanation:
Both arrow methods share a closure over the same 'count' variable, so incrementing it twice sets count to 2.
Correct Answer: b) "function"
Explanation:
The typeof operator explicitly identifies callable function objects as "function".
Correct Answer: b) "function"
Explanation:
Arrow functions are function instances, so typeof returns "function".
Correct Answer: b) They throw a TypeError because they cannot be used as constructors.
Explanation:
Arrow functions lack a [[Construct]] internal method and prototype property, raising a TypeError if called with 'new'.
Correct Answer: b) 1
Explanation:
The length property of a function specifies the number of expected parameters up to the first parameter with a default value.
Correct Answer: a) 1
Explanation:
The inner IIFE forms a closure accessing 'x' from its outer scope, logging 1.
Correct Answer: b) undefined followed by ReferenceError
Explanation:
'var name' is hoisted as undefined. 'let age' is hoisted in the Temporal Dead Zone, throwing a ReferenceError when accessed early.
Correct Answer: b) "undefined"
Explanation:
Named function expressions bind their name exclusively inside their own local body scope, leaving 'fn' undefined outside.
Correct Answer: a) "function"
Explanation:
Inside the function body, the identifier 'fn' refers to the function itself, returning "function".
Correct Answer: c) They produce the same output for identical inputs and have no side effects.
Explanation:
Pure functions depend solely on their parameters and create zero side effects outside their local scope.
Correct Answer: b) 10
Explanation:
In non-strict mode, parameters in standard functions map dynamically to the arguments object slots.
Correct Answer: a) 1
Explanation:
In strict mode, the arguments object is decoupled from formal parameter variables, keeping 'a' equal to 1.
Correct Answer: a) Bob
Explanation:
The arrow function inherits 'this' lexically from person.greet()'s context, where 'this' points to person.
Correct Answer: a) Converting a multi-argument function into a sequence of functions taking one argument each.
Explanation:
Currying transforms f(a, b, c) into callable nested functions f(a)(b)(c).
Correct Answer: a) 24
Explanation:
Each nested arrow function captures its argument via closure: 2 * 3 * 4 = 24.
Correct Answer: b) 20
Explanation:
Lexical scoping rules look up variables from the inner function's static definition environment, capturing local x = 20.
Correct Answer: b) window/global object (in non-strict mode)
Explanation:
In non-strict mode, passing null or undefined to call/apply replaces 'this' with the global object.
Correct Answer: a) null
Explanation:
In strict mode, call/apply retains the exact 'this' argument passed, remaining null.
Correct Answer: b) A Promise resolving to the returned value
Explanation:
Async functions always wrap their return values inside a resolved Promise.
Correct Answer: a) 42
Explanation:
foo() returns a resolved Promise containing 42, which .then() receives as 'val'.
Correct Answer: c) await
Explanation:
The await operator pauses async function execution until the target Promise settles.
Correct Answer: b) Returns { x: 20 }
Explanation:
When a constructor explicitly returns a non-null object, that object overrides the newly constructed instance.
Correct Answer: b) Returns { x: 10 }
Explanation:
If a constructor explicitly returns a primitive value (like 5), the primitive is ignored and the created instance is returned.
Correct Answer: b) false
Explanation:
The 'arguments' object is an array-like object with length and indexed elements, but it is not an instance of Array.
Correct Answer: d) All of the above
Explanation:
Array.from(), spread syntax, and slice.call() are all valid techniques to transform array-like objects into true arrays.
Correct Answer: a) A function that invokes itself.
Explanation:
A recursive function resolves problems by repeatedly calling itself until reaching a base condition.
Correct Answer: b) RangeError: Maximum call stack size exceeded
Explanation:
Unbounded recursion fills the browser execution call stack, leading to a maximum call stack size RangeError.
Correct Answer: a) "fn"
Explanation:
ES6 assigns automatic name inference to anonymous functions assigned to variables.
Correct Answer: a) 1 followed by 2
Explanation:
Calling g.next() yields objects containing { value, done }. Accessing .value retrieves 1 on first call and 2 on second call.
Correct Answer: a) { value: undefined, done: true }
Explanation:
Once a generator exhausts its yield statements, subsequent .next() invocations return { value: undefined, done: true }.
Correct Answer: b) undefined
Explanation:
The declaration 'var a' is hoisted to the top of the function scope, but its value remains undefined until assignment.
Correct Answer: c) ReferenceError
Explanation:
Variables declared with 'let' remain in the Temporal Dead Zone (TDZ) prior to declaration, throwing a ReferenceError.
Correct Answer: b) Parameters are names defined in function signature; arguments are real values passed during invocation.
Explanation:
Parameters are placeholder variable names listed in function headers; arguments are actual values supplied when calling.
Correct Answer: b) undefined
Explanation:
The inner function expression loses the 'obj' binding when invoked as a standalone function call `()`, so this.x is undefined.
Correct Answer: d) Both a and c
Explanation:
Arrow functions lexically inherit 'this' from fn(), and .bind(this) explicitly preserves 'this'.
Correct Answer: b) 1
Explanation:
function.length counts parameters before the first default parameter, returning 1.
Correct Answer: b) 0
Explanation:
Since the very first parameter 'a' has a default value, length counts 0 parameters prior to it.
Correct Answer: a) 1
Explanation:
Functions created with the `Function` constructor are always evaluated in global scope, referencing global a = 1.
Correct Answer: a) Alice: Hello
Explanation:
bind() pre-binds parameters (partial application). Here "Hello" binds to parameter 'msg', ignoring subsequent arguments passed to boundSay.
Correct Answer: a) Caching function results based on arguments to speed up future executions.
Explanation:
Memoization is an optimization technique that stores computed results of pure functions for repeated parameter values.
Correct Answer: a) "undefined" "number"
Explanation:
b = 3 creates an unintended global variable 'b' (in non-strict mode), while 'var a' is scoped to the IIFE. typeof a is "undefined" and typeof b is "number".
Correct Answer: a) ReferenceError: b is not defined
Explanation:
In strict mode, assigning a value to an undeclared variable (b = 3) throws a ReferenceError.
Correct Answer: a) Inside
Explanation:
Function declaration bar() is hoisted above the return statement in foo(), allowing execution.
Correct Answer: b) TypeError: bar is not a function
Explanation:
'var bar' is hoisted as undefined. Invoking return bar() before assignment attempts to call undefined, throwing a TypeError.
Correct Answer: a) An empty array []
Explanation:
When no matching arguments are provided, rest parameters evaluate to an empty array [].
Correct Answer: a) "object"
Explanation:
Rest parameters collect arguments into an Array instance. In JavaScript, typeof arrays yields "object".
Correct Answer: a) true
Explanation:
Array.isArray correctly identifies the rest parameter ...args as a true Array instance.
Correct Answer: a) A function passed as an argument to another function to be executed later.
Explanation:
Callback functions are passed into higher-order functions to be invoked at a designated time during execution.
Correct Answer: a) 10
Explanation:
The inline arrow callback (x => x * 2) receives base (5) and returns 5 * 2 = 10.
Correct Answer: a) Nested callbacks forming deep pyramids of code that are difficult to read and maintain.
Explanation:
Callback hell describes deeply nested callback chains that hinder code readability and exception handling.
Correct Answer: a) Promises and async/await
Explanation:
Promises and async/await offer clean, linear control flow syntax to manage asynchronous operations.
Correct Answer: a) { a: 1 }
Explanation:
Using explicit return statements inside arrow function curly braces correctly returns the object { a: 1 }.
Correct Answer: a) undefined
Explanation:
Curly braces without parentheses are parsed as a function block, interpreting 'a:' as a statement label and returning undefined.
Correct Answer: a) const fn = () => ({ a: 1 });
Explanation:
Wrapping an object literal in parentheses `({ ... })` tells JavaScript to evaluate the expression as an implicit object return.
Correct Answer: a) 3
Explanation:
Function y modifies the local parameter variable x (initialized to 2), updating it to 3 within the parameter scope.
Correct Answer: a) IIFE
Explanation:
IIFEs (Immediately Invoked Function Expressions) run setup logic instantly while keeping variables isolated.
Correct Answer: a) 20
Explanation:
Explicit binding via .call(obj2) overrides object method invocation, setting 'this' to obj2.
Correct Answer: b) The bound function retains the context established by the first bind() call.
Explanation:
Hard binding established by the first .bind() call cannot be overridden by subsequent .bind() calls.
Correct Answer: a) 1
Explanation:
Bound functions permanently retain their initial bound 'this' target ({ a: 1 }), ignoring later .call() re-bindings.
Correct Answer: a) "object"
Explanation:
In JavaScript, the internal type of the arguments object returns "object".
Correct Answer: a) Using call() or apply() to run a method of one object on another object.
Explanation:
Method borrowing allows an object to reuse another object's function by setting 'this' via call or apply.
Correct Answer: a) true
Explanation:
Borrowing Array.prototype.slice converts array-like objects (having indices and length) into true Array instances.
Correct Answer: a) A function that creates and returns a new object without using the 'new' keyword.
Explanation:
Factory functions are regular functions that construct and return object instances directly.
Correct Answer: a) Eve
Explanation:
The returned object method forms a closure encapsulating the 'name' parameter ("Eve").
Correct Answer: a) Yes, local variables defined inside the factory function are accessible only by enclosed methods.
Explanation:
Factory functions leverage function scope and closures to keep internal state variables private.
Correct Answer: a) Returns a Generator object conforming to Iterator and Iterable protocols.
Explanation:
Invoking a generator function creates and returns an unstarted Generator iterator object.
Correct Answer: a) {value: 1, done: false}, {value: 2, done: true}, {value: undefined, done: true}
Explanation:
A 'return' statement inside a generator finishes iteration early, returning { value: 2, done: true }. Subsequent yields are ignored.
Correct Answer: a) 2
Explanation:
Variable 'a' declared inside inner() shadows variable 'a' in outer(), logging 2.
Correct Answer: a) 2
Explanation:
The inner function holds a reference to variable 'a'. When inner() runs, 'a' has already been reassigned to 2.
Correct Answer: a) Breaking a complex function into smaller, manageable, and reusable pure functions.
Explanation:
Decomposition reduces complexity by splitting monolithic tasks into smaller single-purpose functions.
Correct Answer: a) 1 2 3
Explanation:
Passing 'undefined' for 'b' activates its default value (2), so arguments print as 1 2 3.
Correct Answer: a) 1 null 3
Explanation:
Default parameter values are triggered ONLY by 'undefined'. Passing 'null' explicitly assigns null to b.
Correct Answer: a) Combining two or more functions to produce a new function (e.g., f(g(x))).
Explanation:
Function composition passes the output of one function as the input argument to another function.
Correct Answer: a) 36
Explanation:
double(3) evaluates to 6. Then square(6) evaluates to 36.
Correct Answer: a) 18
Explanation:
square(3) evaluates to 9. Then double(9) evaluates to 18.
Correct Answer: a) 60
Explanation:
Array.from converts 'arguments' to a true array, allowing reduce to calculate 10 + 20 + 30 = 60.
Correct Answer: a) 60
Explanation:
The rest parameter syntax collects parameters into a true Array instance directly, summing to 60.
Correct Answer: c) They can be used as constructor functions with 'new'.
Explanation:
Arrow functions lack construct capabilities and throw a TypeError if called with 'new'.
Correct Answer: a) "function"
Explanation:
test() returns the un-invoked inner function definition, so typeof yields "function".
Correct Answer: a) Inner
Explanation:
test() returns the inner function, and the trailing `()` invokes it immediately, returning "Inner".
Correct Answer: a) 2
Explanation:
inc() modifies the global variable 'count' twice through side effects, setting count to 2.
Correct Answer: a) They make code state unpredictable, harder to test, and introduce unexpected bugs.
Explanation:
Avoiding side effects guarantees predictable function outputs and simplifies testing.
Correct Answer: a) 1
Explanation:
obj.b() binds 'this' to obj during execution. The returned arrow function lexically retains this context, yielding 1.
Correct Answer: a) undefined
Explanation:
detachedB() is invoked without an explicit object receiver, causing 'this' inside b to evaluate to global/undefined, so this.a is undefined.
Correct Answer: a) 6
Explanation:
Parameter b evaluates expression a * 2 (3 * 2), outputting 6.
Correct Answer: a) 10
Explanation:
Providing an explicit argument (10) overrides the default parameter expression.
Correct Answer: b) forEach()
Explanation:
forEach runs side effects for each element in an array and always returns undefined.
Correct Answer: a) filter()
Explanation:
filter() creates a new array populated with elements that evaluate to truthy in the callback test.
Correct Answer: a) map()
Explanation:
map() transforms every element of an array based on the callback's return value and produces a new array of identical length.
Correct Answer: a) [2, 4, 6]
Explanation:
map multiplies each array element by 2, returning a new array [2, 4, 6].
Correct Answer: a) [2, 4]
Explanation:
filter retains elements that satisfy even condition `x % 2 === 0`, yielding array [2, 4].
Correct Answer: a) Hello followed by undefined
Explanation:
console.log("Hello") prints "Hello" and returns undefined. test() returns that undefined value, which is then logged.
Correct Answer: a) Creates a function dynamically from string arguments.
Explanation:
The Function constructor compiles functions dynamically from strings representing parameter names and function body code.
Correct Answer: a) 1
Explanation:
The delete operator removes properties from objects. It cannot delete local function parameters or variables, so 'a' remains 1.
Related Posts

Latest Python Dictionaries MCQs
Python dictionaries are built-in data structures used to store data in key-value pairs, providing fast lookups, insertions, and deletions. Keys…
October 19, 2026By MCQs Generator

Java Functions MCQs
In Java, functions are formally known as methods and serve as modular blocks of reusable code encapsulated within classes. A…
October 19, 2026By MCQs Generator

C++ Memory Management MCQs
Memory management in C++ empowers developers with direct control over hardware resources, primarily through the allocation and deallocation of memory…
October 20, 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