JavaScript MCQs with answers Page - 13

Here, you will find a collection of MCQ questions on JavaScript. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833K Points
Coach

Q. What will happen if we execute the following piece of code?

Code:
<script>  
  
var arr=[4,3,,1];    
  for(i=0;i<4;i++){  
document.writeln(arr[i]);  
}  
</script>  
  • (A) The output will be 4 3 1
  • (B) The output will be 4 3 undefined 1
  • (C) It will result in an error
  • (D) It does not run at all

A

Admin • 833K Points
Coach

Q. What output we may get if we execute the following JavaScript code

Code:
<script>  
function myFunction() {  
  
  var i;  
  for (i = 0; i< 5; i++) {  
    if (i === 3) {  
      continue;  
    }  
document.write(i);  
  }  
  
}  
myFunction();  
</script>  
  • (A) 0124
  • (B) 01234
  • (C) It will throw a error
  • (D) No output

A

Admin • 833K Points
Coach

Q. What will be the output of the following JavaScript code?

Code:
<script>  
var string1=[1,2,3];  
  
var string2=[4,5,6,7,8,9,10];  
var result=string1.concat(string2);  
document.writeln(result);  
</script>  
  • (A) 1, 2, 3
  • (B) Error
  • (C) It will concatenate both the stings and print as 1, 2, 3, 4, 5, 6, 7, 8, 9 ,10
  • (D) It will print nothing

A

Admin • 833K Points
Coach

Q. What is the primary role of the "return ()" statement in a function body?

  • (A) It returns the value and continues executing rest of the statements
  • (B) It returns the value and stops the program execution
  • (C) Stops executing the function and returns the value
  • (D) It returns the value and stops executing the function

A

Admin • 833K Points
Coach

Q. If a function which does not return a value is known as

  • (A) Static function
  • (B) Procedures
  • (C) Method
  • (D) Dynamic function

A

Admin • 833K Points
Coach

Q. The execution of a function stops when the program control encounters the _________ statement in the body of the function.

  • (A) return statement
  • (B) continue statement
  • (C) break statement
  • (D) goto statement

A

Admin • 833K Points
Coach

Q. In which events/scenarios, A function name gets optional in JavaScript?

  • (A) When a function is defined as a looping statement
  • (B) When the function is called
  • (C) When a function is defined as expressions
  • (D) When the function is predefined

A

Admin • 833K Points
Coach

Q. In JavaScript, the definition of a function starts with____

  • (A) With the Return type, Function keyword, Identifier and Parentheses
  • (B) With the Identifier and Parentheses
  • (C) With the Return type and Identifier
  • (D) With the Identifier and Return type

A

Admin • 833K Points
Coach

Q. What happens if the return statement has no related expression?

  • (A) It will return a undefined value
  • (B) It will throw a exception
  • (C) It will return the 0 as the value
  • (D) It will throw a error

A

Admin • 833K Points
Coach

Q. Which one of the following options is the correct output for the given code of JavaScript?

Code:
<script>  
functionprintprops(o)  
{  
for(var ain o)  
console.log(a+": "+ o[a]+"
");  
}  
</script>  
  • (A) Prints the contents of each property of o
  • (B) Prints the address of elements
  • (C) Prints only one property
  • (D) Returns undefined

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ