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
"What is the purpose of the `<script>` tag in HTML?"
Answer
The `<script>` tag is used to embed or reference JavaScript code within an HTML document so it can interact with the page content.
How can you display a simple message to users using JavaScript?
Answer
You can use the `alert()` function to show a popup message to users.
Why should you place JavaScript code at the end of the `<body>` tag?
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.
What does the `prompt()` function do in JavaScript?
Answer
The `prompt()` function displays a dialog box asking the user for input, and returns the value as a string.
How do you change the content of an HTML element using JavaScript?
Answer
You can use `document.getElementById("id").innerHTML = "new content";` to change the content of an HTML element.
"What is the purpose of the `src` attribute in the `<script>` tag?"
Answer
The `src` attribute is used to include an external JavaScript file in an HTML document.
What is the primary purpose of JavaScript in web development?
Which JavaScript method is used to display a message in a browser's pop-up window?
Answer
How does JavaScript interact with HTML and CSS?
Where is the recommended place to include JavaScript code in an HTML document?
"What is the purpose of the `defer` attribute in a `<script>` tag?"
Which of the following is a valid way to declare a variable in JavaScript?
What will the following code output?
var a = 5;
var b = 10;
var c = a + b;
console.log(c);
Can a variable in JavaScript hold different data types at different times?
How do you define a function in JavaScript?
What does the following function do?
function greet() {
alert("Welcome to JavaScript!");
}
greet();
How can you pass parameters to a function in JavaScript?
What is the purpose of the `prompt()` method in JavaScript?
How can you capture the value entered by a user using `prompt()`?
What type of value does `prompt()` return?
Which method is used to change the content of an HTML element in JavaScript?
How would you change the content of an element with the id "demo" to "Hello World"?
document.getElementById("demo").innerHTML = "Hello World";
Why is manipulating the DOM important in web development?
What is the advantage of using an external JavaScript file?
How do you link an external JavaScript file to an HTML document?
<script src="path/to/your/script.js"></script>
"Where should the `<script>` tag be placed when linking to an external JavaScript file?"
🧠 Practice & Progress
Explore More Topics
JavaScript Fundamentals
Math
Events