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 is the primary difference between arrow functions and regular functions in terms of this?

View

What will this code print? const myFunc = () => { return this; }; console.log(myFunc());

View

Can arrow functions be used as methods within objects?

View

What will the following code output? const myObj = { x: 10, getX: () => this.x }; console.log(myObj.getX());

View

Which of the following is true about regular functions?

View

What will be the result of this code? function Foo() { this.val = 42; return () => this.val; } let f = new Foo(); console.log(f());

View

Why might arrow functions not be suitable as constructors?

View

What will this code log? let x = 5; const add = (a) => a + x; console.log(add(3));

View

Which of the following will result in a syntax error for arrow functions?

View

What will this code output? let obj = { id: 1, getId: function() { return () => this.id; } }; console.log(obj.getId()());

View

What is the primary difference between arrow functions and regular functions in terms of this?

Arrow functions have their own this context
Arrow functions inherit this from their surrounding context
Regular functions don’t bind this
Arrow functions bind this globally

What will this code print? const myFunc = () => { return this; }; console.log(myFunc());

The global object (window in browsers)
Undefined
Error
The function itself

Can arrow functions be used as methods within objects?

Yes, but they will not have their own this
No, arrow functions cannot be used in objects
Yes, they behave like regular methods
Only in strict mode

What will the following code output? const myObj = { x: 10, getX: () => this.x }; console.log(myObj.getX());

10
Undefined
Error
Null

Which of the following is true about regular functions?

They do not have their own this context
They can bind to any object with this
They must be used within objects
They cannot access this in global scope

What will be the result of this code? function Foo() { this.val = 42; return () => this.val; } let f = new Foo(); console.log(f());

42
Undefined
Error
null

Why might arrow functions not be suitable as constructors?

Because they don't bind their own this
Because they cannot return objects
Because they always return undefined
Because they don't accept parameters

What will this code log? let x = 5; const add = (a) => a + x; console.log(add(3));

3
8
Undefined
Error

Which of the following will result in a syntax error for arrow functions?

Declaring them without parentheses for single arguments
Using this inside the function
Using them as constructors
Returning objects in single-expression format

What will this code output? let obj = { id: 1, getId: function() { return () => this.id; } }; console.log(obj.getId()());

1
Undefined
Error
Null