menu

JavaScript Functions


1. What is a higher-order function in JavaScript?

A function that takes another function as an argument

A function that returns another function

A function that accesses variables outside its own scope

A function that is used to create objects


2. What is the purpose of the "bind" method in JavaScript?

To create a new function with a specified "this" value and arguments provided as an array

To create a new object with a specified prototype object and properties

To call a function with a specified "this" value and arguments provided as individual arguments

To bind a function to a specific "this" value


3. What is the purpose of the "this" keyword in a JavaScript function?

To refer to the function itself

To refer to the global object

To refer to the object that the function is a method of

To refer to the previous function in the call stack


4. What is the purpose of the "arguments" object in a JavaScript function?

To store the function name

To store the function code

To store the function parameters

To store the function return value


5. Which of the following is a way to create a closure in JavaScript?

Returning a function from another function

Using the "with" statement

Using the "debugger" statement

Using the "switch" statement


6. What is a closure in JavaScript?

A function that takes another function as an argument

A function that returns another function

A function that accesses variables outside its own scope

A function that is used to create objects


7.

What is the output of the following code snippet?

function myFunction(x, y) {
console.log(x + y);
}
myFunction(2, 3, 4);

5

9

11

Error


8. What is the difference between function declarations and function expressions in JavaScript?

Function declarations use the "function" keyword, while function expressions use the "=>" operator

Function declarations are hoisted, while function expressions are not hoisted

Function declarations must have a name, while function expressions do not require a name

Function declarations can be assigned to variables, while function expressions cannot be assigned to variables


9.

What is the output of the following code snippet?

var x = 1;
function myFunction() {
console.log(x);
}
myFunction();

undefined

null

0

1


10. What is the purpose of the "apply" method in JavaScript?

To call a function with a specified "this" value and arguments provided as an array

To call a function with a specified "this" value and arguments provided as individual arguments

To create a new object with a specified prototype object and properties

To bind a function to a specific "this" value