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?

  1. <js>
  2. <code>
  3. <script>
  4. <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?

  1. show()
  2. popup()
  3. alert()
  4. 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?

  1. At the top of the <head> tag
  2. In the middle of the <body>
  3. Just before the closing </body> tag
  4. 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?

  1. input()
  2. getInput()
  3. prompt()
  4. 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?

  1. textValue
  2. htmlContent
  3. value
  4. 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?

  1. href
  2. link
  3. src
  4. path
Answer

src

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


๐ŸŸก Intermediate

๐Ÿ”ด Advanced


๐Ÿง  Practice & Progress

Explore More Topics