Q. Which keyword is used to define a JavaScript function?

  • (A) module
  • (B) fun
  • (C) func
  • (D) function
πŸ’¬ Discuss
βœ… Correct Answer: (D) function

Q. Which is the correct syntax for the function definition?

  • (A) return_type function function_name(parameter1, parameter2, ...) { /*Function's body*/ }
  • (B) function function_name(parameter1, parameter2, ...) { /*Function's body*/ }
  • (C) return_type function_name(parameter1, parameter2, ...) { /*Function's body*/ }
  • (D) function function_name(parameter1, parameter2, ...) as return_type { /*Function's body*/ }
πŸ’¬ Discuss
βœ… Correct Answer: (B) function function_name(parameter1, parameter2, ...) { /*Function's body*/ }

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

Code:
<script>
	function addition(a, b) {
		return a+b;
	}
	document.getElementById("test").innerHTML = addition;
</script>
  • (A) SyntaxError
  • (B) ValueError
  • (C) 0
  • (D) function addition(a, b) { return a+b; }
πŸ’¬ Discuss
βœ… Correct Answer: (D) function addition(a, b) { return a+b; }

Q. In JavaScript a variable contains one value while an object may contain ___.

  • (A) One value
  • (B) Two values
  • (C) Three values
  • (D) Many values
πŸ’¬ Discuss
βœ… Correct Answer: (D) Many values

Q. Which is the correct syntax to access an object property in JavaScript?

  • (A) objectName:propertyName
  • (B) propertyName
  • (C) objectName["propertyName"]
  • (D) Both B and C.
πŸ’¬ Discuss
βœ… Correct Answer: (D) Both B and C.

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

  • (A) strlen
  • (B) len
  • (C) lenght
  • (D) Length
πŸ’¬ Discuss
βœ… Correct Answer: (C) lenght

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

Q. Which character is used to break up a code line within a text string in JavaScript?

  • (A) Single quote (')
  • (B) Single backslash (\)
  • (C) Double quote (")
  • (D) Tipple single quote (''')
πŸ’¬ Discuss
βœ… Correct Answer: (B) Single backslash (\)

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
πŸ’¬ Discuss
βœ… Correct Answer: (A) var s = new String("IncludeHelp!");

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