menu

JavaScript Functions


1. 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 call a function with a specified "this" value and arguments provided as individual arguments

To bind a function to a specific "this" value

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


2.

What is the output of the following code snippet?

function myFunction(x) {
return function(y) {
return x + y;
};
}
var addFive = myFunction(5);
var result = addFive(10);
console.log(result);

5

10

15

20


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 "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


5. 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


6. 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


7. What is the difference between a named function and an anonymous function in JavaScript?

Named functions can be called from anywhere in the code, while anonymous functions cannot be called

Anonymous functions are defined without a name, while named functions have a name

Named functions are hoisted, while anonymous functions are not hoisted

Anonymous functions can be assigned to variables, while named functions cannot be assigned to variables


8. Which of the following is not a valid JavaScript function parameter passing method?

Pass by value

Pass by reference

Pass by pointer

Pass by object


9. What is a closure in JavaScript?

A function that is called at the end of a program's execution

A function that is called when an event occurs

A function that is passed as an argument to another function

A combination of a function and the lexical environment in which it was declared


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

A function that returns a boolean value

A function that takes another function as an argument or returns a function as a result

A function that performs a specific task

A function that is called when an event occurs