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 Topics:


  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 Topics:


  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 Topics:


  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 Topics:


  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 Topics:


  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 Topics:


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

  14. 💬 Answer

    
    
    
    

    📘 Related Topics:


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


  16. How does JavaScript interact with HTML and CSS?

  17. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

  19. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

  21. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

  23. 💬 Answer

    
    
    
    

    📘 Related Topics:


  24. What will the following code output?

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

    💬 Answer

    
    
    
    

    📘 Related Topics:


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

  27. 💬 Answer

    
    
    
    

    📘 Related Topics:


  28. How do you define a function in JavaScript?

  29. 💬 Answer

    
    
    
    

    📘 Related Topics:


  30. What does the following function do?

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

    💬 Answer

    
    
    
    

    📘 Related Topics:


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

  33. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

  35. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

  37. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

  39. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

  41. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

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

    💬 Answer

    
    
    
    

    📘 Related Topics:


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

  45. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

  47. 💬 Answer

    
    
    
    

    📘 Related Topics:


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

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

    💬 Answer

    
    
    
    

    📘 Related Topics:


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

  51. 💬 Answer

    
    
    
    

    📘 Related Topics: