Function Fundamentals

Last Updated :
Discuss
Comments

Question 1

Which of the following is true about function declarations in JavaScript?

  • A

    They are not hoisted.

  • B

    They are hoisted to the top of their scope.

  • C

    They can be invoked only after they are defined.

  • D

    They cannot accept parameters.

Question 2

What happens if a function is declared inside another function?


  • A

    The inner function is accessible globally.

  • B

    The outer function gets overwritten by the inner function.

  • C

    The inner function is only accessible inside the outer function.

  • D

    Both functions are inaccessible.

Question 3

Which of the following is an example of method invocation?

  • A

    add(3, 5)

  • B

    new Person("Alex", 25)

  • C

    greet("John")

  • D

    user.greet()

Question 4

Which function invocation method is used to invoke a function and explicitly set the this value?

  • A

    apply()

  • B

    bind()

  • C

    call()

  • D

    Direct invocation

Question 5

What is the output of the following code?

JavaScript
const user = { name: "Alice" };
const greet = () => `Hello, ${this.name}!`;
console.log(greet.call(user));


  • A

    Hello, undefined!

  • B

    Hello, Alice!

  • C

    Hello, this.name!

  • D

    Error: Cannot read this

Question 6

What will be the output of this code?

JavaScript
const greet = () => {
  return { name: "John" };
};
console.log(greet());


  • A

    { name: "John" }

  • B

    undefined

  • C

    John

  • D

    Hello, undefined!

Question 7

Which of the following is NOT a valid way to declare a function in JavaScript?

  • A

    Function Declaration

  • B

    Function Expression

  • C

    Arrow Function

  • D

    Function Constructor

Question 8

What happens when a function expression is used in a callback?

  • A

    The function is executed immediately.

  • B

    The function is hoisted and executed before the callback.

  • C

    The function is executed once the event occurs.

  • D

    The callback is ignored.

Question 9

What will be the output of this code?

JavaScript
const greet = (name) => `Hello, ${name}`;
console.log(greet("Alice"));


  • A

    undefined

  • B

    Alice

  • C

    Hello, undefined

  • D

    Hello, Alice

Question 10

What will be the output of the following code?

JavaScript
const numbers = [1, 2, 3];
numbers.forEach(function(num) {
  num = num * 2;
});
console.log(numbers);


  • A

    [1, 2, 3]

  • B

    [2, 4, 6]

  • C

    [1, 4, 9]

  • D

    [1, 2, 3, 6]

There are 10 questions to complete.

Take a part in the ongoing discussion