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


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


4.

What is the output of the following code snippet?

function myFunction(x) {
x = x + 1;
return x;
}
var y = 2;
myFunction(y);
console.log(y);

2

3

undefined

Error


5. What is the purpose of a function parameter?

To pass values into a function

To declare variables inside a function

To define a function's name

To specify a function's return value


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 a JavaScript function?

A keyword used to define variables

A set of instructions that perform a specific task

A method used to create objects

An object that contains properties and methods


8. What is a callback function in JavaScript?

A function that is called when an event occurs

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

A function that is passed as an argument to another function and is executed when the other function is finished

A function that is used to create objects


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


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