Learn with Yasir
Share Your Feedback

Review Questions on Javascript Basics – Test Your Understanding

Reinforce your Python OOP inheritance knowledge with review questions designed to test your grasp of single, multiple, and multilevel inheritance. Ideal for students and beginners.

🔍 Review Questions

  1. "What is the purpose of the `<script>` tag in HTML?"

  2. Answer

    The `<script>` tag is used to embed or reference JavaScript code within an HTML document so it can interact with the page content.

    📚 Related Resources:


  3. How can you display a simple message to users using JavaScript?

  4. Answer

    You can use the `alert()` function to show a popup message to users.

    📚 Related Resources:


  5. Why should you place JavaScript code at the end of the `<body>` tag?

  6. Answer

    Placing JavaScript at the end of the body allows the HTML content to load first, improving page performance and preventing errors related to accessing unrendered elements.

    📚 Related Resources:


  7. What does the `prompt()` function do in JavaScript?

  8. Answer

    The `prompt()` function displays a dialog box asking the user for input, and returns the value as a string.

    📚 Related Resources:


  9. How do you change the content of an HTML element using JavaScript?

  10. Answer

    You can use `document.getElementById("id").innerHTML = "new content";` to change the content of an HTML element.

    📚 Related Resources:


  11. "What is the purpose of the `src` attribute in the `<script>` tag?"

  12. Answer

    The `src` attribute is used to include an external JavaScript file in an HTML document.

    📚 Related Resources:


  13. What is the primary purpose of JavaScript in web development?


  14. Which JavaScript method is used to display a message in a browser's pop-up window?

  15. Answer

    📚 Related Resources:


  16. How does JavaScript interact with HTML and CSS?


  17. Where is the recommended place to include JavaScript code in an HTML document?


  18. "What is the purpose of the `defer` attribute in a `<script>` tag?"


  19. Which of the following is a valid way to declare a variable in JavaScript?


  20. What will the following code output?

  21. var a = 5;
    var b = 10;
    var c = a + b;
    console.log(c);
    

  22. Can a variable in JavaScript hold different data types at different times?


  23. How do you define a function in JavaScript?


  24. What does the following function do?

  25. function greet() {
      alert("Welcome to JavaScript!");
    }
    greet();
    

  26. How can you pass parameters to a function in JavaScript?


  27. What is the purpose of the `prompt()` method in JavaScript?


  28. How can you capture the value entered by a user using `prompt()`?


  29. What type of value does `prompt()` return?


  30. Which method is used to change the content of an HTML element in JavaScript?


  31. How would you change the content of an element with the id "demo" to "Hello World"?

  32. document.getElementById("demo").innerHTML = "Hello World";
    

  33. Why is manipulating the DOM important in web development?


  34. What is the advantage of using an external JavaScript file?


  35. How do you link an external JavaScript file to an HTML document?

  36. <script src="path/to/your/script.js"></script>
    

  37. "Where should the `<script>` tag be placed when linking to an external JavaScript file?"



🧠 Practice & Progress

Explore More Topics