Unit 3 - Practice Quiz

INT219 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 What is the primary function of the Execution Context in JavaScript?

A. To manage the memory heap allocation for objects.
B. To define the environment in which JavaScript code is evaluated and executed.
C. To compilation JavaScript code into machine code before execution.
D. To handle HTTP requests and responses asynchronously.

2 In the context of the Scope Chain, what happens when a variable is not found in the immediate local scope?

A. The engine throws a ReferenceError immediately.
B. The engine declares the variable in the local scope automatically.
C. The engine looks up the scope chain to the outer (lexical) environment.
D. The engine returns undefined.

3 Which of the following creates a Closure?

A. A function defined inside another function that accesses variables from the outer function.
B. Any function that uses global variables.
C. A function that returns a Promise.
D. A class extending another class.

4 Consider the following code snippet. What will be logged to the console?

javascript
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}

A. 0, 1, 2
B. 1, 2, 3
C. 3, 3, 3
D. undefined, undefined, undefined

5 How can the issue in the previous question (printing 3, 3, 3) be fixed to print 0, 1, 2 using ES6 syntax?

A. Use const instead of var.
B. Use let instead of var.
C. Wrap the setTimeout in a Promise.
D. Increase the timeout duration.

6 What is the Temporal Dead Zone (TDZ)?

A. The time between a network request and the response.
B. The period between entering a scope and the actual declaration of a let or const variable.
C. The state of a Promise before it resolves.
D. Code that is never executed in a switch statement.

7 In the JavaScript Prototype Chain, if you access a property on an object, where does the engine look first?

A. It looks at Object.prototype.
B. It looks at the object's own properties.
C. It looks at the object's __proto__.
D. It looks at the Global object.

8 What is the result of Object.getPrototypeOf(func) === Function.prototype for a standard function func?

A. true
B. false
C. undefined
D. null

9 Which method is used to create a new object with a specified prototype object and properties?

A. Object.new()
B. Object.make()
C. Object.create()
D. Object.construct()

10 What key component of the JavaScript runtime is responsible for handling asynchronous callbacks?

A. The Heap
B. The Call Stack
C. The Event Loop
D. The Parser

11 Is JavaScript single-threaded or multi-threaded?

A. Multi-threaded
B. Single-threaded
C. Single-threaded but processes Microtasks in parallel
D. It depends on the browser

12 Which of the following is added to the Microtask Queue?

A. setTimeout callbacks
B. setInterval callbacks
C. Promise.then callbacks
D. I/O events

13 Consider the following code. What is the order of execution?

javascript
console.log('A');
setTimeout(() => console.log('B'), 0);
Promise.resolve().then(() => console.log('C'));
console.log('D');

A. A, B, C, D
B. A, D, B, C
C. A, D, C, B
D. A, C, D, B

14 What are the three possible states of a Promise?

A. Start, Process, End
B. Pending, Fulfilled, Rejected
C. Waiting, Done, Error
D. Sent, Received, Failed

15 What does the async keyword do when placed before a function declaration?

A. It forces the function to run on a separate thread.
B. It pauses the execution of the global script.
C. It ensures the function always returns a Promise.
D. It makes the function synchronous.

16 How does await affect the execution context inside an async function?

A. It blocks the main thread until the Promise resolves.
B. It pauses the execution of the async function until the Promise resolves.
C. It creates a new thread for the Promise.
D. It cancels the Promise if it takes too long.

17 What is the difference between Promise.all() and Promise.allSettled()?

A. Promise.all waits for all to complete regardless of result; Promise.allSettled fails if one fails.
B. Promise.all fails fast if any input promise rejects; Promise.allSettled waits for all to finish regardless of status.
C. They are identical alias methods.
D. Promise.allSettled only accepts synchronous functions.

18 In ES6, what is the behavior of the arrow function => regarding the this keyword?

A. It creates a new this scope.
B. It ignores this completely.
C. It lexically binds this (inherits it from the surrounding scope).
D. It binds this to the global object always.

19 What will the following code output?

javascript
const obj = {
a: 10,
b: () => console.log(this.a)
};
obj.b();

A. 10
B. undefined
C. null
D. ReferenceError

20 Which ES6 feature allows you to extract data from arrays or objects into distinct variables?

A. Concatenation
B. Destructuring assignment
C. Template literals
D. Spread syntax

21 What is the output of the following spread syntax usage?

javascript
const arr1 = [1, 2];
const arr2 = [...arr1, 3, 4];

A. [[1, 2], 3, 4]
B. [1, 2, 3, 4]
C. [1, 2, [3, 4]]
D. SyntaxError

22 What is the primary difference between a Map and a plain Object in ES6?

A. Objects allow keys of any type; Maps only allow strings.
B. Maps do not inherit from Object.
C. Maps allow keys of any type (including objects); Objects historically allow only strings/symbols.
D. Maps are slower than Objects.

23 Which statement correctly exports a default value from an ES6 module?

A. export default myFunction;
B. export myFunction;
C. module.exports = myFunction;
D. default export myFunction;

24 How do you import a named export { data } and rename it to info?

A. import { data as info } from './module';
B. import data: info from './module';
C. import { data -> info } from './module';
D. import { info } from './module';

25 When using type="module" in a script tag, what is the default behavior regarding execution timing?

A. It blocks parsing until executed.
B. It is deferred (defer) by default.
C. It is executed asynchronously (async).
D. It executes immediately.

26 What is Hoisting?

A. Moving a DOM element to the top of the body.
B. The behavior where variable and function declarations are moved to the top of their scope during compilation.
C. Raising the priority of a thread.
D. Importing a module from a CDN.

27 What is the output of console.log(x) if var x = 5 is declared on the next line?

A. ReferenceError
B. 5
C. undefined
D. null

28 Which queue has higher priority in the Event Loop?

A. Macrotask Queue
B. Microtask Queue
C. Callback Queue
D. Render Queue

29 What does Promise.race() do?

A. Waits for the fastest Promise to resolve.
B. Waits for the fastest Promise to settle (resolve or reject).
C. Runs all Promises in parallel and returns an array.
D. Stops the slowest Promise.

30 Which ES6 structure is best suited for maintaining a list of unique values?

A. Array
B. Map
C. Set
D. Object

31 What defines the value of this in a standard function call (not arrow, not strict mode)?

A. Where the function is declared.
B. How the function is called.
C. The type of the function.
D. The file it is located in.

32 How can you manually set the this context for a function call?

A. Using .bind(), .call(), or .apply()
B. Using .setThis()
C. Using .context()
D. It is impossible to manually set this.

33 What is a WeakMap?

A. A Map that only holds primitive keys.
B. A Map where keys are weakly referenced, allowing garbage collection if there are no other references to the key.
C. A Map that has limited methods.
D. A Map that is not thread-safe.

34 What is the purpose of the module pattern (using IIFE and Closures) in pre-ES6 JavaScript?

A. To speed up execution.
B. To create private scope and encapsulate data.
C. To allow multi-threading.
D. To support classes.

35 What happens if you await a non-Promise value? e.g., await 10;

A. It throws a TypeError.
B. It returns 10 immediately.
C. It wraps the value in a resolved Promise and waits for the microtask queue.
D. It causes an infinite loop.

36 Which of the following is an example of a Macrotask?

A. process.nextTick (Node.js)
B. Promise.resolve().then(...)
C. queueMicrotask(...)
D. setInterval(...)

37 What is the output of console.log(typeof class {});?

A. "class"
B. "object"
C. "function"
D. "prototype"

38 What is the Rest Parameter syntax?

A. function f(...args)
B. function f(args...)
C. function f($args)
D. function f(args[])

39 What characterizes Strict Mode ('use strict') regarding this in a standalone function?

A. this defaults to the Global Object.
B. this defaults to undefined.
C. this defaults to the function itself.
D. this causes a syntax error.

40 Why is it generally discouraged to modify Object.prototype directly?

A. It is read-only.
B. It affects every object in the application, potentially leading to conflicts.
C. It throws a security error.
D. It disables garbage collection.

41 Which ES2020 feature allows accessing deeply nested properties without checking existence at each level?

A. Nullish Coalescing (??)
B. Optional Chaining (?.)
C. Logical OR (||)
D. Object.assign

42 What is the purpose of the super keyword in an ES6 Class?

A. To declare a super global variable.
B. To call the constructor or methods of the parent class.
C. To define the superior method.
D. To access the DOM root.

43 What is a Generator Function?

A. A function that automatically generates random numbers.
B. A function that can be paused and resumed, declared with function*.
C. A function that creates new classes.
D. A factory function for DOM elements.

44 In the context of Modules, what does Tree Shaking refer to?

A. Randomizing the order of imports.
B. Removing unused code (dead code elimination) during the build process.
C. Refreshing the browser automatically.
D. Structuring the folder hierarchy.

45 How do you create a Dynamic Import?

A. import('./module').then(...)
B. require('./module')
C. fetch('./module')
D. load('./module')

46 What is the output of console.log(1 + '1')?

A. 2
B. "11"
C. NaN
D. TypeError

47 What does the finally block in a Promise chain do?

A. It runs only if the promise is rejected.
B. It runs only if the promise is resolved.
C. It runs regardless of whether the promise was resolved or rejected.
D. It terminates the script.

48 In a closure, where are the captured variables stored?

A. On the Call Stack.
B. In the Heap.
C. In the CPU registers.
D. In LocalStorage.

49 What is Currying?

A. Mixing multiple spices.
B. Transforming a function with multiple arguments into a sequence of functions each taking a single argument.
C. Calling a function recursively.
D. Binding this to a function.

50 Which symbol is used for Template Literals?

A. Single quotes '
B. Double quotes "
C. Backticks `
D. Hyphens -