Learn with Yasir

Share Your Feedback

JavaScript Basics MCQs: Test Your Knowledge with Practice Questions


Enhance your understanding of JavaScript fundamentals by practicing multiple-choice questions covering variables, functions, loops, and more.

📝 Multiple Choice Questions

🟢 Beginner

Q1. What tag is used to write JavaScript in an HTML document?

  • 🟢 A. <js>
  • 🔵 B. <code>
  • 🟠 C. <script>
  • 🔴 D. <javascript>
Answer

<script>

The <script> tag is used to add JavaScript to HTML pages.


Q2. Which JavaScript function is used to show a message in a popup box?

  • 🟢 A. show()
  • 🔵 B. popup()
  • 🟠 C. alert()
  • 🔴 D. display()
Answer

alert()

The alert() function displays a popup message to the user.


Q3. Where is it considered best practice to place the <script> tag in an HTML document?

  • 🟢 A. At the top of the <head> tag
  • 🔵 B. In the middle of the <body>
  • 🟠 C. Just before the closing </body> tag
  • 🔴 D. Inside a <div> tag
Answer

Just before the closing </body> tag

Placing JavaScript at the end of the body ensures HTML content loads before the script runs.


Q4. How do you take input from the user in JavaScript?

  • 🟢 A. input()
  • 🔵 B. getInput()
  • 🟠 C. prompt()
  • 🔴 D. ask()
Answer

prompt()

prompt() is used to collect input from users through a dialog box.


Q5. Which property is used to change the content of an HTML element?

  • 🟢 A. textValue
  • 🔵 B. htmlContent
  • 🟠 C. value
  • 🔴 D. innerHTML
Answer

innerHTML

innerHTML lets you get or set the content inside an HTML element.


Q6. Which attribute is used in the <script> tag to include an external JavaScript file?

  • 🟢 A. href
  • 🔵 B. link
  • 🟠 C. src
  • 🔴 D. path
Answer

src

The src attribute is used to link an external JavaScript file in the <script> tag.


🟡 Intermediate

🔴 Advanced