menu

JavaScript Functions


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


2. Which of the following is not a JavaScript function declaration method?

Function constructor

Function expression

Function literal

Function prototype


3.

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


4. What is the purpose of the "new" keyword in JavaScript?

To create a new variable

To create a new object instance

To declare a new function

To import a module


5. What is the purpose of the "apply" and "call" methods 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


6. What is the purpose of the "this" keyword in JavaScript?

To refer to the current object

To refer to the previous object

To refer to the next object

To refer to a global variable


7. What is a rest parameter in JavaScript?

A parameter that is required for a function to work properly

A parameter that has a default value if no value is provided

A parameter that is ignored by a function

A parameter that allows a function to accept an indefinite number of arguments as an array


8.

What is the output of the following code snippet?

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

10

5

undefined

Error


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


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