🎓🚀 Challenge Time: Test Your JavaScript Knowledge! 💡🖥️
LEARN JAVASCRIPT
QUIZ 16 Questions
1. What is the correct syntax for referring to an external script called script.js?
A. <script name="script.js">
B. <script href="script.js">
C. <script src="script.js">
D. <script link="script.js">
Answer: C
2. How do you create a function in JavaScript?
A. function:myFunction()
B. function = myFunction()
C. function myFunction()
D. function => myFunction()
Answer: C
3. How to write an if statement in JavaScript?
A. if (i == 5)
B. if i = 5
C. if i == 5 then
D. if i = 5 then
Answer: A
4. How does a while loop start?
A. while (i <= 10; i++)
B. while i = 1 to 10
C. while (i <= 10)
D. while (i++)
Answer: C
5. How can you add a comment in JavaScript?
A. <!--This is a comment-->
B. //This is a comment
C. /* This is a comment */
D. Both B and C
Answer: D
6. What is the correct way to write a JavaScript array?
A. var colors = (1:"red", 2:"green", 3:"blue")
B. var colors = "red", "green", "blue"
C. var colors = ["red", "green", "blue"]
D. var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")
Answer: C
7. Which event occurs when the user clicks on an HTML element?
A. onmouseclick
B. onchange
C. onclick
D. onmouseover
Answer: C
8. How do you declare a JavaScript variable?
A. v variableName;
B. variable variableName;
C. var variableName;
D. let variableName;
Answer: C
Recommended by LinkedIn
9. Which operator is used to assign a value to a variable?
A. *
B. -
C. =
D. x
Answer: C
10. What will the following code return: Boolean(10 > 9)
A. NaN
B. false
C. true
D. undefined
Answer: C
11. What is the correct JavaScript syntax to change the content of the HTML element below?
html
Copy code
<p id="demo">This is a demonstration.</p>
A. document.getElement("p").innerHTML = "Hello World!";
B. document.getElementById("demo").innerHTML = "Hello World!";
C. #demo.innerHTML = "Hello World!";
D. document.getElementByName("p").innerHTML = "Hello World!";
Answer: B
12. Where is the correct place to insert a JavaScript?
A. Both the <head> section and the <body> section are correct
B. The <body> section
C. The <head> section
D. The <footer> section
Answer: A
13. How do you write "Hello World" in an alert box?
A. msgBox("Hello World");
B. alert("Hello World");
C. msg("Hello World");
D. alertBox("Hello World");
Answer: B
14. How do you create an object in JavaScript?
A. var person = {firstName:"John", lastName:"Doe"};
B. var person = Object("John", "Doe");
C. var person = new Object("John", "Doe");
D. var person = (firstName:"John", lastName:"Doe");
Answer: A
15. Which operator is used to check if two values are equal and of the same type?
A. =
B. ==
C. ===
D. !=
Answer: C
16. How do you find the number with the highest value of x and y?
A. top(x, y)
B. Math.max(x, y)
C. Math.ceil(x, y)
D. ceil(x, y)
Answer: B