JavaScript Online Test

This post presents the JavaScript Online Test with 25 multiple-choice questions for beginners. These beginner-level MCQ questions cover the fundamentals of JavaScript.

1. What is JavaScript primarily used for?

a) Styling web pages
b) Building operating systems
c) Creating interactive websites
d) Data storage on servers

2. Which of the following is a valid variable declaration in JavaScript?

a) int number = 5;
b) var number = 5;
c) float number = 5.0;
d) string text = "hello";

3. What does the alert() function do?

a) Closes the current window
b) Displays a message box to the user
c) Changes the background color of the page
d) Sends an alert to the server

4. How do you create a function in JavaScript?

a) function = myFunction()
b) function myFunction()
c) create myFunction()
d) function:myFunction()

5. Which of the following is used to parse a string to an integer?

a) int.parse()
b) Integer.parse()
c) parseInt()
d) parse.Int()

6. How do you write a conditional statement that executes some code if "i" is NOT equal to 5?

a) if i <> 5 {}
b) if (i != 5) {}
c) if i not 5 {}
d) if (i !== 5) {}

7. Which object is used to handle the browser window?

a) Browser
b) Doc
c) Window
d) Screen

8. What does the document.getElementById() method return?

a) The class of the element
b) The first element with the specified class name
c) The element that matches the specified ID
d) All elements with the specified name

9. What is the correct syntax for adding comments in JavaScript?

a) <!–This is a comment–>
b) # This is a comment
c) /* This is a comment */
d) // This is a comment

10. What keyword is used to declare a constant in JavaScript?

a) constant
b) const
c) var
d) let

11. Which method would you use to round a number to the nearest integer?

a) Math.round()
b) Math.rnd()
c) Math.nearest()
d) Number.round()

12. How do you find the number with the highest value of x and y using JavaScript?

a) top(x, y)
b) Math.ceil(x, y)
c) Math.max(x, y)
d) Math.highest(x, y)

13. What is the purpose of the Array.push() method?

a) It connects two arrays together.
b) It removes the last element of an array.
c) It adds one or more elements to the end of an array.
d) It finds an element in an array.

14. What does "DOM" stand for in JavaScript?

a) Document Object Model
b) Display Object Management
c) Digital Ordinance Model
d) Document Ordinance Model

15. How is event handling done in JavaScript?

a) Using trigger functions
b) Using implicit invocation
c) Using (handle:event) pairs
d) Using event listeners

16. What is the difference between == and === in JavaScript?

a) They mean the same thing.
b) == compares only value; === compares both value and type.
c) == compares only type; === compares both value and type.
d) There is no === operator in JavaScript.

17. What does the splice() method do in an array?

a) Finds the index of an item in the array.
b) Removes or replaces existing elements and/or adds new elements.
c) Copies a portion of the array into a new array.
d) Joins two or more arrays.

18. How do you declare a JavaScript variable that will change over time?

a) var variableName;
b) let variableName;
c) const variableName;
d) dec variableName;

19. What is JSON in JavaScript?

a) JavaScript Object Notation
b) Java Standard Output Network
c) JavaScript Output Naming
d) Java Source Open Network

20. Which method converts a JavaScript object to a JSON string?

a) JSON.toString()
b) JSON.stringify()
c) JSON.toArray()
d) JSON.parse()

21. What method is used to parse a string as JSON, optionally transforming the value produced by parsing?

a) JSON.fromString()
b) JSON.parse()
c) JSON.decode()
d) JSON.toObject()

22. How do you stop the execution of a setInterval() timer function?

a) clearInterval(timerId)
b) stopInterval(timerId)
c) endInterval(timerId)
d) deleteInterval(timerId)

23. What is a Promise in JavaScript?

a) A multi-threading model
b) An agreement to perform in the future
c) An object that may produce a single value some time in the future
d) A function that returns an array

24. Which HTML tag is NOT necessary for JavaScript code?

a) <script>
b) <head>
c) <meta>
d) <link>

25. How do you write an "if" statement in JavaScript for executing some code if "x" is equal to 2?

a) if x = 2 then
b) if x == 2
c) if (x = 2)
d) if (x == 2)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top