Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What will the following code output?

View

What is the output of the following code?

View

What does the following code output?

View

Which of the following correctly illustrates prototype inheritance?

View

What will the following code output?

View

What is the main advantage of using the module pattern?

View

What is the output of the following code?

View

What will the following code output?

View

What is the output of the following code?

View

Which of the following is a characteristic of closures?

View

What will the following code output?

<p>function create() {<br>&nbsp; let name = "Closure";<br>&nbsp; return function() {<br>&nbsp; &nbsp; return name;<br>&nbsp; };<br>}<br>const getName = create();<br>console.log(getName());<br><br></p>

Closure
undefined
Error
null

What is the output of the following code?

<p>var x = 1;<br>(function() {<br>&nbsp; var x = 2;<br>&nbsp; console.log(x);<br>})();<br>console.log(x);<br><br></p>

1, 2
2, 1
2, 2
1, 1

What does the following code output?

<p>const moduleA = (function() {<br>&nbsp; let privateVar = "I am private";<br>&nbsp; return {<br>&nbsp; &nbsp; getPrivate: function() {<br>&nbsp; &nbsp; &nbsp; return privateVar;<br>&nbsp; &nbsp; }<br>&nbsp; };<br>})();<br>console.log(moduleA.getPrivate());<br><br></p>

I am private
undefined
Error
null

Which of the following correctly illustrates prototype inheritance?

Child.prototype = Parent;
Child.prototype = Object.create(Parent.prototype);
Child.prototype = new Parent();
Child.prototype = Parent.prototype;

What will the following code output?

<p>let a = 10;<br>function test() {<br>&nbsp; console.log(a);<br>&nbsp; var a = 20;<br>}<br>test();<br><br></p>

10
20
undefined
null

What is the main advantage of using the module pattern?

It creates global variables
It allows encapsulation and prevents pollution of the global scope
It simplifies function declarations
It allows inheritance

What is the output of the following code?

<p>function Parent() {}<br>function Child() {}<br>Child.prototype = Object.create(Parent.prototype);<br>const childInstance = new Child();<br>console.log(childInstance instanceof Parent);<br><br></p>

true
false
Error
undefined

What will the following code output?

<p>let count = 0;<br>const incrementCounter = (function() {<br>&nbsp; return function() {<br>&nbsp; &nbsp; count++;<br>&nbsp; &nbsp; return count;<br>&nbsp; };<br>})();<br>console.log(incrementCounter());<br>console.log(incrementCounter());<br><br></p>

1, 1
1, 2
0, 1
0, 0

What is the output of the following code?

<p>console.log(a);<br>var a = 10;<br>console.log(a);<br><br></p>

10, 10
undefined, 10
10, undefined
Error

Which of the following is a characteristic of closures?

They can only access variables defined in the outer function
They are destroyed after the outer function returns
They can access variables from the global scope
They can be garbage collected immediately after execution