JavaScript Functions

JavaScript Functions Quiz

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What is the purpose of a function in JavaScript?

  1. To group related code together
  2. To reuse code in different parts of a program
  3. To pass data between different parts of a program
  4. All of the above
Question 2 Multiple Choice (Single Answer)

How do you define a function in JavaScript?

  1. function functionName() {}
  2. functionName() {}
  3. var functionName = function() {}
  4. var functionName = {}
Question 3 Multiple Choice (Single Answer)

How do you call a function in JavaScript?

  1. functionName();
  2. functionName
  3. functionName = ();
  4. functionName {}
Question 4 Multiple Choice (Single Answer)

What is the difference between a function declaration and a function expression?

  1. Function declarations are hoisted, while function expressions are not.
  2. Function expressions can be used as values, while function declarations cannot.
  3. Function declarations can be named, while function expressions cannot.
  4. All of the above
Question 5 Multiple Choice (Single Answer)

What is the this keyword in JavaScript?

  1. It refers to the current object
  2. It refers to the global object
  3. It refers to the function that is being called
  4. It refers to the parent object
Question 6 Multiple Choice (Single Answer)

What is the difference between arguments and parameters in JavaScript?

  1. Arguments are the values passed to a function when it is called, while parameters are the variables that are declared in the function definition.
  2. Parameters are the values passed to a function when it is called, while arguments are the variables that are declared in the function definition.
  3. Arguments and parameters are the same thing.
  4. None of the above
Question 7 Multiple Choice (Single Answer)

What is a callback function?

  1. A function that is passed as an argument to another function
  2. A function that is called from within another function
  3. A function that is defined inside another function
  4. All of the above
Question 8 Multiple Choice (Single Answer)

What is the difference between a synchronous function and an asynchronous function?

  1. Synchronous functions execute immediately, while asynchronous functions execute after some time.
  2. Asynchronous functions execute immediately, while synchronous functions execute after some time.
  3. Synchronous functions can be paused and resumed, while asynchronous functions cannot.
  4. Asynchronous functions can be paused and resumed, while synchronous functions cannot.
Question 9 Multiple Choice (Single Answer)

What is a higher-order function?

  1. A function that takes another function as an argument
  2. A function that returns another function
  3. A function that can be called multiple times
  4. All of the above
Question 10 Multiple Choice (Single Answer)

What is the bind() method in JavaScript?

  1. It creates a new function that, when called, has its this keyword set to the provided value.
  2. It creates a new function that, when called, has its arguments pre-filled with the provided values.
  3. It creates a new function that, when called, has its return value set to the provided value.
  4. None of the above
Question 11 Multiple Choice (Single Answer)

What is the apply() method in JavaScript?

  1. It calls a function with a given this value and arguments provided as an array.
  2. It calls a function with a given this value and arguments provided as individual parameters.
  3. It calls a function with a given this value and no arguments.
  4. None of the above
Question 12 Multiple Choice (Single Answer)

What is the call() method in JavaScript?

  1. It calls a function with a given this value and arguments provided as individual parameters.
  2. It calls a function with a given this value and arguments provided as an array.
  3. It calls a function with a given this value and no arguments.
  4. None of the above
Question 13 Multiple Choice (Single Answer)

What is the difference between the bind(), apply(), and call() methods in JavaScript?

  1. The bind() method creates a new function, while the apply() and call() methods call an existing function.
  2. The apply() method takes an array of arguments, while the call() method takes individual arguments.
  3. The bind() method can only be used with arrow functions, while the apply() and call() methods can be used with any function.
  4. None of the above
Question 14 Multiple Choice (Single Answer)

What is a closure in JavaScript?

  1. A function that has access to the variables of its outer scope, even after the outer scope has finished executing.
  2. A function that is defined inside another function.
  3. A function that can be called multiple times.
  4. None of the above
Question 15 Multiple Choice (Single Answer)

What is the difference between a global variable and a local variable in JavaScript?

  1. Global variables are declared outside of any function, while local variables are declared inside a function.
  2. Global variables are accessible from anywhere in the program, while local variables are only accessible from within the function in which they are declared.
  3. Global variables can be reassigned, while local variables cannot.
  4. All of the above