Q. In JavaScript, multi-line comments start with __ and end with ___.

  • (A) /* and */
  • (B) <!—and -->
  • (C) ## and ##
  • (D) // and //
πŸ’¬ Discuss
βœ… Correct Answer: (A) /* and */

Q. Which JavaScript keyword is used to declare a variable?

  • (A) Var
  • (B) var
  • (C) Let
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) var

Q. How many keywords are there in JavaScript to declare variables or constants?

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4
πŸ’¬ Discuss
βœ… Correct Answer: (C) 3

Q. What is the main difference between var and let keywords in JavaScript?

  • (A) var defines a variable while let defines a constant
  • (B) var defined function scoped variable while let define block scoped variable
  • (C) The value of a variable declared with var can be changed while the value of a variable declared with let cannot be changed
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) var defined function scoped variable while let define block scoped variable

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
πŸ’¬ Discuss
βœ… Correct Answer: (C) Constant

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;
πŸ’¬ Discuss
βœ… Correct Answer: (D) const constant_name = value;

Q. What will be the value of VALUE?

Code:
<script>
	const VALUE = 10;
	VALUE = 20;
</script>
  • (A) 10
  • (B) 20
  • (C) ValueError
  • (D) TypeError
πŸ’¬ Discuss
βœ… Correct Answer: (D) TypeError

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

  • (A) 0
  • (B) undefined
  • (C) null
  • (D) NaN
πŸ’¬ Discuss
βœ… Correct Answer: (B) undefined

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
πŸ’¬ Discuss
βœ… Correct Answer: (D) NaN

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
πŸ’¬ Discuss
βœ… Correct Answer: (A) Alex Alvin