Software Development Exam  >  Software Development Test  >  JavaScript for Web Development  >  Test: Functions - 2 - Software Development MCQ

Functions - 2 - Free MCQ Practice Test with solutions, Software Development


MCQ Practice Test & Solutions: Test: Functions - 2 (15 Questions)

You can prepare effectively for Software Development JavaScript for Web Development with this dedicated MCQ Practice Test (available with solutions) on the important topic of "Test: Functions - 2". These 15 questions have been designed by the experts with the latest curriculum of Software Development 2026, to help you master the concept.

Test Highlights:

  • - Format: Multiple Choice Questions (MCQ)
  • - Duration: 30 minutes
  • - Number of Questions: 15

Sign up on EduRev for free to attempt this test and track your preparation progress.

Test: Functions - 2 - Question 1

What is a function in JavaScript?

Detailed Solution: Question 1

A function in JavaScript is a reusable block of code that performs a specific task when called.

Test: Functions - 2 - Question 2

What is the difference between parameters and arguments in JavaScript?

Detailed Solution: Question 2

Parameters are the variables defined in a function's declaration, while arguments are the actual values passed to the function when it is called.

Test: Functions - 2 - Question 3

Which of the following statements is true regarding JavaScript functions?

Detailed Solution: Question 3

JavaScript functions can be used before they are declared due to hoisting, which moves function declarations to the top of the scope.

Test: Functions - 2 - Question 4

What is the purpose of the 'return' statement in JavaScript functions?

Detailed Solution: Question 4

The 'return' statement is used to output a value from a function. It also terminates the execution of the function.

Test: Functions - 2 - Question 5

Which keyword is used to call a function in JavaScript?

Detailed Solution: Question 5

The 'call' keyword is used to call a function in JavaScript.

Test: Functions - 2 - Question 6

What will be the output of the following code?
function greet() {
  console.log("Hello!");
}

console.log(typeof greet);

Detailed Solution: Question 6

The 'typeof' operator returns the type of the operand. In this case, it returns "function" because 'greet' is a function.

Test: Functions - 2 - Question 7

What will be the output of the following code?
function sum(a, b) {
  return a + b;
}

var result = sum(3, 4);
console.log(result);

Detailed Solution: Question 7

The 'sum' function returns the sum of its two parameters. When called with 'sum(3, 4)', it returns 7, which is assigned to the 'result' variable and then printed.

Test: Functions - 2 - Question 8

What will be the output of the following code?
function outer() {
  var x = 10;

  function inner() {
    console.log(x);
  }

  return inner;
}

var fn = outer();
fn();

Detailed Solution: Question 8

The 'inner' function is defined inside the 'outer' function and has access to the variables in its parent scope, including 'x'. When 'fn()' is called, it prints the value of 'x', which is 10.

Test: Functions - 2 - Question 9

What will be the output of the following code?
var x = 5;

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

test();

Detailed Solution: Question 9

In the 'test' function, the 'console.log(x)' statement is executed before the 'var x = 10' line. At that point, 'x' is undefined, so it prints undefined.

Test: Functions - 2 - Question 10

What will be the output of the following code?
function multiply(a, b = 2) {
  return a * b;
}

console.log(multiply(3));

Detailed Solution: Question 10

The 'multiply' function accepts two parameters, 'a' and 'b', with 'b' having a default value of 2. When called with 'multiply(3)', it uses the default value of 'b' (2) and returns the product of 'a' (3) and 'b' (2), which is 6.

Test: Functions - 2 - Question 11

What will be the output of the following code?
var x = 10;

function outer() {
  function inner() {
    console.log(x);
  }

  inner();
  var x = 20;
}

outer();

Detailed Solution: Question 11

The 'inner' function is called before the 'x' variable is defined within the 'outer' function. Therefore, when 'console.log(x)' is executed, 'x' is undefined.

Test: Functions - 2 - Question 12

What will be the output of the following code?
function greet(name) {
  console.log("Hello, " + name + "!");
}

greet();

Detailed Solution: Question 12

The 'greet' function expects a parameter 'name' to be passed when called. Since no argument is provided when calling 'greet()', the 'name' parameter is undefined, resulting in the output "Hello, undefined!".

Test: Functions - 2 - Question 13

What will be the output of the following code?
function outer() {
  var x = 10;

  function inner() {
    console.log(x);
  }

  x = 20;
  return inner;
}

var fn = outer();
fn();

Detailed Solution: Question 13

The 'inner' function is defined inside the 'outer' function and has access to the variables in its parent scope, including 'x'. When 'fn()' is called, it prints the value of 'x', which is 10.

Test: Functions - 2 - Question 14

What will be the output of the following code?
var x = 10;

function test() {
  if (x === 10) {
    var x = 20;
  }

  console.log(x);
}

test();

Detailed Solution: Question 14

The 'var x = 20' declaration inside the 'if' statement creates a new variable 'x' with block scope. Since the 'console.log(x)' statement is outside the block, it refers to the outer variable 'x', which is undefined.

Test: Functions - 2 - Question 15

What will be the output of the following code?
function add(a, b) {
  return a + b;
}

function multiply(a, b) {
  return a * b;
}

var result = add(2, multiply(3, 4));
console.log(result);

Detailed Solution: Question 15

The 'multiply' function is called with arguments '3' and '4', returning the result '12'. This result is then passed as an argument to the 'add' function along with '2', resulting in the final result of '14', which is printed.

51 videos|32 docs|12 tests
Information about Test: Functions - 2 Page
In this test you can find the Exam questions for Test: Functions - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Functions - 2, EduRev gives you an ample number of Online tests for practice
Download as PDF