menu

JavaScript Functions


1. Which of the following is a higher-order function in JavaScript?

parseInt()

setTimeout()

Math.abs()

Object.keys()


2. What is the difference between "call" and "apply" methods in JavaScript?

There is no difference between "call" and "apply"

Call method accepts an array of arguments, while "apply" method accepts individual arguments

Call method accepts individual arguments, while "apply" method accepts an array of arguments

Call method is used for asynchronous functions, while "apply" method is used for synchronous functions


3. Which keyword is used to define a JavaScript function that can be called without creating an instance of the object?

static

prototype

class

function


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


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


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


8. What is a spread operator in JavaScript?

An operator that combines two or more arrays into a single array

An operator that assigns a new value to a variable

An operator that creates a new object with a specified prototype object and properties

An operator that allows an iterable object to be expanded into individual elements


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

To specify a function's input parameters

To store a function's local variables

To create a new array of arguments passed to a function

To access all arguments passed to a function as an array-like object


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