What is the output of `typeof []`?
Options: array, object, list, undefined
Correct Answer: object - Arrays are objects in JavaScript. `typeof []` returns 'object'.
Explanation: Arrays are objects in JavaScript. `typeof []` returns 'object'.
Explanation: Objects are not primitive types. Primitives include: string, number, boolean, null, undefined, and symbol.
Explanation: A variable can be declared without being assigned a value, resulting in `undefined`.
Explanation: Both function declarations and function expressions are valid in JavaScript.
Explanation: In the browser global scope, `this` refers to the `window` object.
Explanation: `==` does type coercion (loose equality), while `===` checks both type and value (strict equality).
Explanation: `parseInt` takes two arguments: string and radix. map() passes index as the second argument, causing incorrect parsing.
Explanation: `Object.create(null)` creates an object with no prototype, while `{}` inherits from Object.prototype.
Explanation: The first `.then()` returns 2 (ignoring the resolved value 1). The second `.then()` logs that 2.
Explanation: A closure is a function that has access to variables from its outer (enclosing) scope even after that function has returned.
Explanation: Arrays are passed by reference. y references the same array as x, so pushing to y modifies the original array.
Explanation: JS uses a single-threaded event loop: executes synchronous code → microtasks (Promises) → macrotasks (setTimeout).
Explanation: Synchronous code runs first (1, 3), then microtasks like Promise callbacks (2).
Explanation: Rest parameters (...args) collect arguments into an array. Spread operator (...arr) expands an iterable into individual elements.
Explanation: JavaScript uses automatic garbage collection, primarily with mark-and-sweep algorithms to identify and remove unreachable objects.
Options: array, object, list, undefined
Correct Answer: object - Arrays are objects in JavaScript. `typeof []` returns 'object'.
Options: string, number, boolean, object
Correct Answer: object - Objects are not primitive types. Primitives include: string, number, boolean, null, undefined, and symbol.
Options: Variable declared but not assigned, Variable not declared, Both, Neither
Correct Answer: Variable declared but not assigned - A variable can be declared without being assigned a value, resulting in `undefined`.
Options: function = myFunc() {}, function myFunc() {}, myFunc = function() {}, Both B and C are correct
Correct Answer: Both B and C are correct - Both function declarations and function expressions are valid in JavaScript.
Options: undefined, null, window object, global object
Correct Answer: window object - In the browser global scope, `this` refers to the `window` object.
Options: No difference, == performs type coercion, === checks type and value, === is faster, == is more strict
Correct Answer: == performs type coercion, === checks type and value - `==` does type coercion (loose equality), while `===` checks both type and value (strict equality).
Options: [1, 2, 3], [1, NaN, NaN], [NaN, 2, 3]
Correct Answer: [1, NaN, NaN] - `parseInt` takes two arguments: string and radix. map() passes index as the second argument, causing incorrect parsing.
Options: Both are identical, Creates object without prototype chain, Creates an empty prototype, Returns null
Correct Answer: Creates object without prototype chain - `Object.create(null)` creates an object with no prototype, while `{}` inherits from Object.prototype.
Options: 1, 2, undefined, Promise object
Correct Answer: 2 - The first `.then()` returns 2 (ignoring the resolved value 1). The second `.then()` logs that 2.
Options: A function that closes after execution, A function with access to variables from its outer scope, An object that cannot be modified, A memory leak in JavaScript
Correct Answer: A function with access to variables from its outer scope - A closure is a function that has access to variables from its outer (enclosing) scope even after that function has returned.
Options: 3, 4, Reference error, 3 then 4
Correct Answer: 4 - Arrays are passed by reference. y references the same array as x, so pushing to y modifies the original array.
Options: Processes all synchronous code, then callbacks from microtask queue, then macrotask queue, Processes code in order it appears, Parallel processing with threads, No specific order
Correct Answer: Processes all synchronous code, then callbacks from microtask queue, then macrotask queue - JS uses a single-threaded event loop: executes synchronous code → microtasks (Promises) → macrotasks (setTimeout).
Options: 1, 2, 3, 1, 3, 2, 2, 1, 3, 3, 2, 1
Correct Answer: 1, 3, 2 - Synchronous code runs first (1, 3), then microtasks like Promise callbacks (2).
Options: They are the same, Rest collects arguments, spread expands iterables, Rest expands, spread collects, Rest is for objects, spread is for arrays
Correct Answer: Rest collects arguments, spread expands iterables - Rest parameters (...args) collect arguments into an array. Spread operator (...arr) expands an iterable into individual elements.
Options: Manual memory management required, Mark-and-sweep algorithm to remove unreferenced objects, No garbage collection in JavaScript, Generational garbage collection only
Correct Answer: Mark-and-sweep algorithm to remove unreferenced objects - JavaScript uses automatic garbage collection, primarily with mark-and-sweep algorithms to identify and remove unreachable objects.