JavaScript MCQs with answers Page - 21

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. The const keyword is used to define a ______.

  • (A) Function scopes variable
  • (B) Block scoped variable
  • (C) Constant
  • (D) Constant with no initial value

A

Admin • 833K Points
Coach

Q. Which is the correct syntax to declare a constant in JavaScript?

  • (A) const constant_name;
  • (B) constant_name const;
  • (C) constant_name const = value;
  • (D) const constant_name = value;

A

Admin • 833K Points
Coach

Q. What will be the value of VALUE?

Code:
<script>
	const VALUE = 10;
	VALUE = 20;
</script>
  • (A) 10
  • (B) 20
  • (C) ValueError
  • (D) TypeError

A

Admin • 833K Points
Coach

Q. What is the default value of an uninitialized variable?

  • (A) 0
  • (B) undefined
  • (C) null
  • (D) NaN

A

Admin • 833K Points
Coach

Q. What is the output of the following JavaScript code?

Code:
<script>
	var a;
	document.getElementById("demo").innerHTML = a+1;
</script>
  • (A) 0
  • (B) undefined
  • (C) 1
  • (D) NaN

A

Admin • 833K Points
Coach

Q. What is the output of the following JavaScript code?

Code:
<script>
	var name = "Alex" + " " + "Alvin";
	document.getElementById("demo").innerHTML = name;
</script>
  • (A) Alex Alvin
  • (B) AlexAlvin
  • (C) TypeError
  • (D) ValueError

A

Admin • 833K Points
Coach

Q. What is the output of the following JavaScript code?

Code:
<script>
	var a = 10 + 20 + "5";
	document.getElementById("demo").innerHTML = a;
</script>
  • (A) 35
  • (B) 305
  • (C) TypeError
  • (D) ValueError

A

Admin • 833K Points
Coach

Q. What is the output of the following JavaScript code?

Code:
<script>
	let a = 10;
	let a = 0;
</script>
  • (A) 10
  • (B) 0
  • (C) SyntaxError
  • (D) TypeError

A

Admin • 833K Points
Coach

Q. Which is the exponentiation operator in JavaScript?

  • (A) exp()
  • (B) ^
  • (C) **
  • (D) pow

A

Admin • 833K Points
Coach

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

Code:
<script>
	var x = 5;
	document.getElementById("demo").innerHTML = x--;
</script>
  • (A) 5
  • (B) 4
  • (C) TypeError
  • (D) ValueError