Important JavaScript Question Answers
JavaScript Objective QA
1. Inside which HTML element do we put the JavaScript?
Answer:
<script>
2. What is the correct JavaScript syntax to change the content of the HTML element below?
<p id="demo">This is a demonstration.</p>
Answer:
document.getElementById("demo").innerHTML = "Hello World!";
3. Where is the correct place to insert a JavaScript?
Answer:
Both the <head> section and the <body> section are correct
4. What is the correct syntax for referring to an external script called "xxx.js"?
Answer:
<script href="xxx.js">
Wrong Answer!
5. The external JavaScript file must contain the <script> tag.
Answer:
True
Wrong Answer!
6. How do you write "Hello World" in an alert box?
Answer:
alert("Hello World");
7. How do you create a function in JavaScript?
Answer:
function = myFunction()
Wrong Answer!
8. How do you call a function named "myFunction"?
Answer:
myFunction()
9. How to write an IF statement in JavaScript?
Answer:
if (i == 5)
10. How to write an IF statement for executing some code if "i" is NOT equal to 5?
Answer:
if (i != 5)
11. How does a WHILE loop start?
Answer:
while (i <= 10)
12. How does a FOR loop start?
Answer:
for (i = 0; i <= 5; i++)
14. How to insert a comment that has more than one line?
Answer:
/*This comment has
more than one line*/
15. What is the correct way to write a JavaScript array?
Answer:
var colors = ["red", "green", "blue"]
17. How do you find the number with the highest value of x and y?
Answer:
Math.max(x, y)
19. JavaScript is the same as Java.
Answer:
False
21. Which event occurs when the user clicks on an HTML element?
Answer:
onclick
22. How do you declare a JavaScript variable?
Answer:
var carName;
23. Which operator is used to assign a value to a variable?
Answer:
=
24. What will the following code return: Boolean(10 > 9)
Answer:
true
25. Is JavaScript case-sensitive?
Answer:
Yes
Comments
Post a Comment