menu

JavaScript Functions


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


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


3. What is a default 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 is used to specify the number of times a function should be executed


4.

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


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


6. What is the purpose of the "return" statement in a JavaScript function?

To specify a function's input parameters

To declare variables inside a function

To specify a function's name

To return a value from a function


7.

What is the output of the following code snippet?

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

2, 3

3, 2

2, 2

3, 3


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


9.

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


10. What is the difference between a synchronous and an asynchronous function in JavaScript?

Synchronous functions block the main thread of execution, while asynchronous functions do not block the main thread

Asynchronous functions are faster than synchronous functions

Synchronous functions can be called from anywhere in the code, while asynchronous functions must be called with a callback function

Synchronous functions can handle multiple tasks at once, while asynchronous functions can only handle one task at a time