Q. Which is the correct syntax to call an external JavaScript file in the current HTML document?

  • (A) <script src="jsfile.js"></script>
  • (B) <script href=" jsfile.js"></script>
  • (C) <import src=" jsfile.js"></import>
  • (D) <script link=" jsfile.js"></script>
πŸ’¬ Discuss
βœ… Correct Answer: (A) <script src="jsfile.js"></script>

Q. Which JavaScript method is used to access an HTML element by id?

  • (A) getElementById()
  • (B) getElement(id)
  • (C) getElementById(id)
  • (D) elementById(id)
πŸ’¬ Discuss
βœ… Correct Answer: (C) getElementById(id)

Q. Which property is used to define the HTML content to an HTML element with a specific id?

  • (A) innerText
  • (B) innerContent
  • (C) elementText
  • (D) innerHTML
πŸ’¬ Discuss
βœ… Correct Answer: (D) innerHTML

Q. Which JavaScript method is used to write HTML output?

  • (A) document.write()
  • (B) document.output()
  • (C) console.log()
  • (D) document.writeHTML()
πŸ’¬ Discuss
βœ… Correct Answer: (A) document.write()

Q. Which JavaScript method is used to write on browser's console?

  • (A) console.write()
  • (B) console.output()
  • (C) console.log()
  • (D) console.writeHTML()
πŸ’¬ Discuss
βœ… Correct Answer: (C) console.log()

Q. Which JavaScript method is used to write into an alert box?

  • (A) window.alertHTML()
  • (B) window.alert()
  • (C) window.alertBox()
  • (D) window.alertContent()
πŸ’¬ Discuss
βœ… Correct Answer: (B) window.alert()

Q. Which is the correct JavaScript statement to display "Hello Boss!" into an alert box?

  • (A) alert("Hello Boss!");
  • (B) alert('Hello Boss!');
  • (C) alert(Text:'Hello Boss!');
  • (D) Both A and B.
πŸ’¬ Discuss
βœ… Correct Answer: (D) Both A and B.

Q. Which is the correct JavaScript statement to print the addition of two numbers 10 and 2o in a paragraph whose id is "result"?

  • (A) getElementById("result").innerHTML = 10+20;
  • (B) getElementById("result").innerHTML = "10+20";
  • (C) getElementById("#result").innerHTML = 10+20;
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) getElementById("result").innerHTML = 10+20;

Q. What is the use of this JavaScript statement?

Code:
<button onclick="window.print()">Submit</button>
  • (A) It will write "Submit" on the current Window
  • (B) It will print the content of the current page
  • (C) It will write the content of the current page in the browser’s console
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) It will print the content of the current page

Q. In JavaScript, single line comment begins with ___.

  • (A) #
  • (B) /*
  • (C) $
  • (D) //
πŸ’¬ Discuss
βœ… Correct Answer: (D) //