menu

JavaScript Functions

JavaScript Functions - Important Points


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

A. parseInt()

B. setTimeout()

C. Math.abs()

D. Object.keys()

Discuss Work Space

Answer: option b

Explanation:

A higher-order function is a function that takes a function as an argument or returns a function. setTimeout() is an example of a higher-order function that takes a function as an argument.

37.

What is the output of the following code snippet?

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

A. 2, 3

B. 3, 2

C. 2, 2

D. 3, 3

Discuss Work Space

Answer: option b

Explanation:

The variable x is declared outside the function with a value of 2. Inside the function, a new variable x is declared with a value of 3, which is then logged to the console. Outside the function, the original variable x with a value of 2 is logged to the console.

38.

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

A. 2

B. 3

C. undefined

D. Error

Discuss Work Space

Answer: option a

Explanation:

The function myFunction takes a parameter x and adds 1 to it. However, the function call myFunction(y) does not update the value of y outside the function, so the output is still 2.

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

A. Function constructor

B. Function expression

C. Function literal

D. Function prototype

Discuss Work Space

Answer: option d

Explanation:

Function prototype is not a JavaScript function declaration methoIt is a property of the function object that can be used to add properties and methods to all instances of the function.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now