JavaScript MCQ Questions PDF

Summary

This document contains multiple choice questions (MCQs) about JavaScript programming. The questions cover various JavaScript concepts and topics, testing knowledge of variables, operators, functions, loops, and arrays. Suitable for self-study or practice.

Full Transcript

JavaScript Notes - MCQ Questions 1. What is JavaScript primarily used for? A. Database management B. Adding interactivity to web pages C. Operating system development D. Network configuration Answer: B 2. Which of the following is a valid JavaScript variable name? A. 123abc B. car-na...

JavaScript Notes - MCQ Questions 1. What is JavaScript primarily used for? A. Database management B. Adding interactivity to web pages C. Operating system development D. Network configuration Answer: B 2. Which of the following is a valid JavaScript variable name? A. 123abc B. car-name C. _carName D. var Answer: C 3. What will `x = "5" + 5` evaluate to in JavaScript? A. 10 B. 55 C. "10" D. Error Answer: B 4. What is the purpose of the `break` statement in a loop? A. Skip the current iteration B. End the loop immediately C. Restart the loop D. Execute the next iteration twice Answer: B 5. Which event handler is used to detect when a user clicks on an element? A. onMouseOver B. onSubmit C. onClick D. onKeyPress Answer: C 6. How are arrays indexed in JavaScript? A. From 1 B. From -1 C. From 0 D. From a user-defined starting point Answer: C 7. What is the output of the following script? ```javascript var a = 10; if (a > 5) { console.log("Hello"); } else { console.log("Goodbye"); } ``` A. Hello B. Goodbye C. Error D. Nothing Answer: A 8. What is the correct syntax for declaring a function in JavaScript? A. function myFunction {} B. function: myFunction {} C. function myFunction() {} D. def myFunction() {} Answer: C 9. Which of the following is NOT a data type in JavaScript? A. String B. Boolean C. Integer D. Null Answer: C 10. What will the following code output? ```javascript var x = 5; var y = "5"; console.log(x == y); ``` A. true B. false C. Error D. undefined Answer: A 11. What is the purpose of the `return` statement in a function? A. Define the function's name B. Exit the function and output a value C. Display an alert to the user D. Repeat the function execution Answer: B 12. Which of these is a valid example of using the `Math` object in JavaScript? A. Math.PI = 3.14 B. Math.round(4.7) C. Math.sqrt D. new Math() Answer: B 13. What does the `length` property of an array do? A. Adds elements to the array B. Counts the number of elements in the array C. Resets the array D. Sorts the array in ascending order Answer: B 14. Which of the following will execute a block of code at least once, regardless of the condition? A. for loop B. while loop C. do...while loop D. if statement Answer: C 15. How do you create a new Date object in JavaScript? A. Date myDate = new Date(); B. var myDate = Date(); C. var myDate = new Date(); D. Date myDate(); Answer: C 16. Which comparison operator checks for both value and type equality? A. == B. != C. === D.

Use Quizgecko on...
Browser
Browser