JavaScript MCQs with answers Page - 23

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 • 832.27K Points
Coach

Q. Which property is used to get the length of a string in JavaScript?

  • (A) strlen
  • (B) len
  • (C) lenght
  • (D) Length

A

Admin • 832.27K Points
Coach

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

Code:
<script>
	let str = "IncludeHelp";
	document.getElementById("test").innerHTML = str.length;
</script>
  • (A) 11
  • (B) 12
  • (C) ValueError
  • (D) SyntaxError

A

Admin • 832.27K Points
Coach

Q. Which is the correct JavaScript statement to define string as object?

  • (A) var s = new String("IncludeHelp!");
  • (B) var s = String("IncludeHelp!");
  • (C) var s = "IncludeHelp!"
  • (D) All of the above

A

Admin • 832.27K Points
Coach

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

Code:
<script>
	let str1 = new String("IncludeHelp!");
	let str2 = new String("IncludeHelp!");
	document.getElementById("test").innerHTML = (str1==str2);
</script>
  • (A) true
  • (B) false
  • (C) True
  • (D) False

A

Admin • 832.27K Points
Coach

Q. Which is/are the valid JavaScript method(s) to extract string parts?

  • (A) slice(start, end)
  • (B) substring(start, end)
  • (C) substr(start, length)
  • (D) All of the above

A

Admin • 832.27K Points
Coach

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

Code:
<script>
    let x = "Hello, IncludeHelp!";
    document.getElementById("test").innerHTML = x.slice(-13,-1);
</script>
  • (A) IncludeHelp!
  • (B) IncludeHelp
  • (C) ValueError
  • (D) Hello,

A

Admin • 832.27K Points
Coach

Q. Which JavaScript method is used to get a number as a string?

  • (A) toString()
  • (B) intToString()
  • (C) parseInteger()
  • (D) All of the above

A

Admin • 832.27K Points
Coach

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

Code:
<script>
	var values = [10, 20, 30, 40];
	
	var result = values.reduceRight(function(x,y){
		return (x + y);
	});
	
	document.write("Result: " + result);
</script>
  • (A) Result: 40
  • (B) Result: 70
  • (C) Result: 90
  • (D) Result: 100

A

Admin • 832.27K Points
Coach

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

Code:
<script>
	var cars = ["Honda","Hyundai","Mahindra"];
	
	var result = cars.shift();
	
	document.writeln("Result: ", cars);
</script>
  • (A) Result: Honda,Hyundai,Mahindra
  • (B) Result: Honda
  • (C) Result: Hyundai,Mahindra
  • (D) Result: Honda,Mahindra

A

Admin • 832.27K Points
Coach

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

Code:
<script>
	var cars = ["Honda","Hyundai","Mahindra"];

	var result = cars.unshift("Toyota", "Tata");

	document.writeln("[", result, "] ", cars);
</script>
  • (A) [5] Toyota,Tata,Honda,Hyundai,Mahindra
  • (B) [5]Honda,Hyundai,Mahindra,Toyota,Tata
  • (C) [2] Toyota,Tata
  • (D) [5] Honda,Hyundai,Toyota,Tata,Mahindra

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