100 JavaScript MCQ with Answers (2026 Edition)

Answering JavaScript MCQ or JavaScript quiz questions is a great way to prepare for coding interviews, online tests, competitive exams, or just to test your JS skills.

These MCQs cover important concepts such as variables, data types, functions, loops, operators, the DOM, asynchronous programming, ES6 features, and much more.

JavaScript Multiple Choice Questions

JavaScript is one of the most widely used programming languages in the world, especially for web development, and practising JavaScript MCQ questions is a smart way to test your knowledge, revise important topics, and recall fundamental concepts.

Go through each JavaScript quiz, think about the answer, and then click “Show Answer” to check your response.

Q1. What is JavaScript mainly used for on websites?

A. Designing the layout
B. Styling text
C. Adding interaction and dynamic behavior
D. Hosting the website online

Show Answer

Answer: C

Q2. Which JavaScript command is used to show a popup alert message?

A. popup()
B. show()
C. alert()
D. notify()

Show Answer

Answer: C

Q3. Which keyword allows you to declare a variable that can be reassigned later?

A. const
B. let
C. fixed
D. define

Show Answer

Answer: B

Q4. Which of the following is a valid JavaScript variable name?

A. 3name
B. name#
C. _name
D. first-name

Show Answer

Answer: C

Q5. What data type is used to store true or false values in JavaScript?

A. Number
B. Boolean
C. String
D. LogicalType

Show Answer

Answer: B

Q6. What does the value ‘undefined’ usually represent in JavaScript?

A. A variable without a value assigned
B. A broken script
C. A false condition
D. A number conversion error

Show Answer

Answer: A

Q7. What will console.log(typeof null) output in JavaScript?

A. ‘null’
B. ‘object’
C. ‘undefined’
D. ‘number’

Show Answer

Answer: B

Q8. JavaScript is considered which type of language?

A. Strongly typed
B. Loosely typed
C. Machine language
D. Assembly language

Show Answer

Answer: B

Q9. Which operator checks both value and data type?

A. ==
B. ===
C. =
D. !==

Show Answer

Answer: B

Q10. What is the output of console.log(5);?

A. ‘5’
B. undefined
C. 5
D. null

Show Answer

Answer: C

Q11. What is JavaScript?

A. A markup language
B. A database language
C. A scripting language used mainly for web browsers
D. A server operating system

Show Answer

Answer: C

Q12. Which statement is used to repeat a block of code a specific number of times?

A. repeat
B. for
C. if
D. check

Show Answer

Answer: B

Q13. What does an if statement do in JavaScript?

A. Declares a constant
B. Runs code only when a condition is true
C. Stops execution
D. Creates a loop

Show Answer

Answer: B

Q14. Which of the following is NOT a loop in JavaScript?

A. for
B. while
C. loop
D. do-while

Show Answer

Answer: C

Q15. Which keyword is commonly used to exit a switch case?

A. stop
B. end
C. break
D. close

Show Answer

Answer: C

Q16. Which operator is known as the “strict equality” operator?

A. =
B. ==
C. ===
D. !=

Show Answer

Answer: C

Q17. Which keyword is used to declare a block-scoped variable?

A. var
B. let
C. define
D. scope

Show Answer

Answer: B

Q18. What is JavaScript most commonly executed by?

A. The web browser
B. The server hardware
C. The database engine
D. The operating system kernel

Show Answer

Answer: A

Q19. Which symbol is used for comments that span only one line?

A. #
B. //
C. —
D. **

Show Answer

Answer: B

Q20. Which of the following describes ECMAScript?

A. A browser
B. The official standard that JavaScript follows
C. A CSS library
D. A database engine

Show Answer

Answer: B

Q21. What is a function in JavaScript?

A. A CSS property
B. A reusable block of code
C. A database query
D. A browser event

Show Answer

Answer: B

Q22. How do you define a function in JavaScript?

A. function myFunc() {}
B. create myFunc() {}
C. define myFunc() {}
D. call myFunc() {}

Show Answer

Answer: A

Q23. What will console.log(4 + 6) output?

A. 10
B. “10”
C. 46
D. undefined

Show Answer

Answer: A

Q24. Which keyword is used to create a constant value in JavaScript?

A. let
B. const
C. var
D. constant

Show Answer

Answer: B

Q25. What is a JavaScript variable?

A. A place to store data values
B. A web server
C. A browser shortcut
D. A CSS effect

Show Answer

Answer: A

Q26. Which function converts a JSON string into a JavaScript object?

A. JSON.stringify()
B. JSON.parse()
C. JSON.convert()
D. JSON.decode()

Show Answer

Answer: B

Q27. What is a closure in JavaScript?

A. A way to delete variables
B. A function with access to its outer scope
C. A security feature
D. A loop structure

Show Answer

Answer: B

Q28. What is hoisting in JavaScript?

A. Removing variables
B. Moving declarations to the top
C. Encrypting code
D. Downloading scripts online

Show Answer

Answer: B

Q29. What is an arrow function?

A. A loop type
B. A shorter way to write functions
C. A DOM element
D. A CSS selector

Show Answer

Answer: B

Q30. What is the purpose of the return statement in a function?

A. To stop the browser
B. To exit the function and send back a value
C. To refresh the page
D. To declare a variable

Show Answer

Answer: B

Q31. What is a JavaScript object?

A. A list of ordered values
B. A collection of key–value pairs
C. A database table
D. A CSS class

Show Answer

Answer: B

Q32. Which symbol is used to access object properties?

A. :
B. .
C. #
D. *

Show Answer

Answer: B

Q33. What does the spread operator (…) do with arrays?

A. Compresses them
B. Expands elements individually
C. Deletes values
D. Sorts values alphabetically

Show Answer

Answer: B

Q34. What is a template literal in JavaScript?

A. A string inside quotes
B. A string written with backticks allowing interpolation
C. A JSON object
D. A CSS style rule

Show Answer

Answer: B

Q35. What does the this keyword usually refer to inside a method?

A. The global object only
B. The current object
C. A random value
D. The DOM tree root

Show Answer

Answer: B

Q36. What is an array in JavaScript?

A. A single number
B. A function
C. A list of ordered values
D. A Boolean value

Show Answer

Answer: C

Q37. Which method adds a new element to the end of an array?

A. push()
B. pop()
C. shift()
D. join()

Show Answer

Answer: A

Q38. Which built-in method removes the last array element?

A. delete()
B. pop()
C. remove()
D. trim()

Show Answer

Answer: B

Q39. What is the DOM in JavaScript?

A. A database
B. A programming language
C. A representation of the HTML page structure
D. A CSS rule system

Show Answer

Answer: C

Q40. Which method selects the first element that matches a CSS selector?

A. getElement()
B. select()
C. querySelector()
D. findElement()

Show Answer

Answer: C

Q41. What is an event in JavaScript?

A. A CSS change
B. A browser notification
C. A user action like click or keypress
D. A server update

Show Answer

Answer: C

Q42. Which method prevents a default browser action like form submit?

A. stop()
B. preventDefault()
C. cancel()
D. block()

Show Answer

Answer: B

Q43. What is the Fetch API used for?

A. Styling elements
B. Sending HTTP requests
C. Animating images
D. Storing cookies

Show Answer

Answer: B

Q44. What is NaN in JavaScript?

A. Null value
B. Not a Number
C. A Boolean
D. A function name

Show Answer

Answer: B

Q45. Which keyword is used to write an asynchronous function?

A. await
B. async
C. defer
D. promise

Show Answer

Answer: B

Q46. What does the JavaScript debugger statement do?

A. Deletes variables
B. Acts as a breakpoint during debugging
C. Restarts the script
D. Closes the browser tab

Show Answer

Answer: B

Q47. What is a Promise in JavaScript?

A. A loop
B. A placeholder for a future value
C. A string method
D. A DOM element type

Show Answer

Answer: B

Q48. What is the purpose of the await keyword?

A. To pause execution until a Promise is resolved
B. To declare a function
C. To create a loop
D. To define a variable

Show Answer

Answer: A

Q49. What will console.log(NaN === NaN) return?

A. true
B. false
C. undefined
D. error

Show Answer

Answer: B

Q50. What does the toString() method do?

A. Converts a string to a number
B. Converts a value to a string
C. Converts text to upper case
D. Removes spaces from text

Show Answer

Answer: B

Q51. Which array method runs a function on every element?

A. loop()
B. repeat()
C. forEach()
D. every()

Show Answer

Answer: C

Q52. What does toLocaleString() generally return?

A. A browser language code
B. A number formatted based on the user’s region
C. A CSS color name
D. A JSON object string

Show Answer

Answer: B

Q53. Which method replaces part of a string using a pattern?

A. change()
B. swap()
C. replace()
D. update()

Show Answer

Answer: C

Q54. What does the map() method return?

A. The same array modified
B. A new array with transformed values
C. A Boolean result
D. A random number

Show Answer

Answer: B

Q55. Which of the following is true about JavaScript variable names?

A. They must start with a letter or _
B. They are case-sensitive
C. Both A and B
D. None of the above

Show Answer

Answer: C

Q56. Which command prints the current page?

A. print.page()
B. browser.print()
C. window.print()
D. page.print()

Show Answer

Answer: C

Q57. What is a global variable in JavaScript?

A. A variable created inside a function
B. A variable available everywhere
C. A constant value
D. A built-in object property

Show Answer

Answer: B

Q58. Which property returns the length of a string?

A. value
B. count
C. length
D. size

Show Answer

Answer: C

Q59. What does valueOf() return when used on a Boolean?

A. A string
B. A number
C. The primitive Boolean value
D. undefined

Show Answer

Answer: C

Q60. Which method converts a string to lowercase?

A. lower()
B. toLowerCase()
C. caseLower()
D. stringLower()

Show Answer

Answer: B

Q61. What is an arrow function commonly used for?

A. Shorter function expressions
B. Loop creation
C. Styling pages
D. Storing data in localStorage

Show Answer

Answer: A

Q62. Which JavaScript array method removes and returns the last element?

A. pop()
B. remove()
C. last()
D. tail()

Show Answer

Answer: A

Q63. Which method converts an array into a string?

A. stringify()
B. toString()
C. convert()
D. cast()

Show Answer

Answer: B

Q64. Which HTML tag is used to include JavaScript code?

A. <code>
B. <js>
C. <script>
D. <run>

Show Answer

Answer: C

Q65. How do you access an element with id=”title” in JavaScript?

A. document.get(“title”)
B. document.title()
C. document.getElementById(“title”)
D. document.id(“title”)

Show Answer

Answer: C

Q66. How do you link an external JavaScript file named app.js?

A. <script file=”app.js”></script>
B. <script src=”app.js”></script>
C. <js src=”app.js”></js>
D. <script href=”app.js”></script>

Show Answer

Answer: B

Q67. What will console.log(5 + “5”) output?

A. 10
B. “10”
C. “55”
D. error

Show Answer

Answer: C

Q68. What does lastIndexOf() return when the value is not found?

A. 0
B. null
C. undefined
D. −1

Show Answer

Answer: D

Q69. Is JavaScript the same as Java?

A. Yes
B. No
C. Only in ES6
D. Only in web browsers

Show Answer

Answer: B

Q70. What will eval(“3 * 4”) return?

A. “12”
B. 12
C. 34
D. 3.4

Show Answer

Answer: B

Q71. Which method selects all matching elements in the DOM?

A. querySelector()
B. querySelectorAll()
C. getElement()
D. selectAll()

Show Answer

Answer: B

Q72. Which queue handles Promise callbacks?

A. Render queue
B. Task queue
C. Microtask queue
D. Event queue

Show Answer

Answer: C

Q73. Which HTTP header helps prevent clickjacking?

A. Cache-Control
B. Content-Type
C. X-Frame-Options
D. Access-Control-Allow-Methods

Show Answer

Answer: C

Q74. Why is eval() generally avoided?

A. It is slow
B. It can be unsafe with user input
C. It increases code size
D. All of the above

Show Answer

Answer: D

Q75. Which command is used to install a package in Node.js?

A. node install
B. install npm
C. npm install
D. npm run install

Show Answer

Answer: C

Q76. Which method reads a file asynchronously in Node.js?

A. fs.read()
B. fs.readFile()
C. fs.readFileSync()
D. fs.openFile()

Show Answer

Answer: B

Q77. Which Web API allows storing data in the browser that remains even after closing the tab?

A. sessionStorage
B. localStorage
C. cacheStorage
D. clipboard API

Show Answer

Answer: B

Q78. Which DOM property returns the parent element of a node?

A. parentElement
B. rootNode
C. ownerNode
D. baseNode

Show Answer

Answer: A

Q79. Which Promise method resolves as soon as any promise is settled?

A. Promise.all()
B. Promise.allSettled()
C. Promise.race()
D. Promise.resolve()

Show Answer

Answer: C

Q80. What type of scope is created when using let inside a block?

A. Function scope
B. Global scope
C. Class scope
D. Block scope

Show Answer

Answer: D

Q81. Which built-in function returns the smallest value?

A. Math.smallest()
B. Math.min()
C. Math.low()
D. Math.floor()

Show Answer

Answer: B

Q82. Which event fires when a user clicks an element?

A. onchange
B. onhover
C. onclick
D. onpress

Show Answer

Answer: C

Q83. What is the difference between JavaScript and Java?

A. They are the same
B. JavaScript is mainly browser-based scripting
C. JavaScript is compiled
D. JavaScript is a database language

Show Answer

Answer: B

Q84. Which method rounds a number to the nearest integer?

A. Math.floor()
B. Math.ceil()
C. Math.round()
D. Math.fix()

Show Answer

Answer: C

Q85. Which of the following correctly creates an array?

A. var list = {1,2,3}
B. var list = [1,2,3]
C. var list = (1,2,3)
D. var list = “1,2,3”

Show Answer

Answer: B

Q86. Which syntax correctly starts a for loop?

A. for (i < 5; i++)
B. for i = 1 to 5
C. for (i = 0; i < 5; i++)
D. loop(i < 5)

Show Answer

Answer: C

Q87. Which syntax correctly starts a while loop?

A. while i < 10
B. while (i < 10)
C. loop while (i < 10)
D. repeat (i < 10)

Show Answer

Answer: B

Q88. Which operator checks if two values are not equal?

A. !=
B. <>
C. !===
D. not=

Show Answer

Answer: A

Q89. Which operator checks strict equality?

A. =
B. ==
C. ===
D. eq

Show Answer

Answer: C

Q90. How do you call a JavaScript function named runTest?

A. function runTest
B. call runTest
C. exec runTest()
D. runTest()

Show Answer

Answer: D

Q91. Which syntax correctly defines a function?

A. define run(){}
B. function run(){}
C. create run(){}
D. make run(){}

Show Answer

Answer: B

Q92. Which syntax correctly writes a multi-line comment?

A. # comment
B. // comment
C. <!– comment –>
D. /* comment */

Show Answer

Answer: D

Q93. Which syntax correctly writes a single-line comment?

A. # comment
B. // comment
C. /* comment */
D. — comment

Show Answer

Answer: B

Q94. Is JavaScript case-sensitive?

A. Yes
B. No
C. Only variable names
D. Only functions

Show Answer

Answer: A

Q95. Where can JavaScript code be placed in an HTML page?

A. Only in the head
B. Only in the body
C. Either head or body
D. Only in external files

Show Answer

Answer: C

Q96. What is the type of null in JavaScript?

A. null
B. object
C. undefined
D. number

Show Answer

Answer: B

Q97. Which keyword declares a variable with block scope?

A. global
B. var
C. let
D. scope

Show Answer

Answer: C

Q98. Which operator checks equality without converting types?

A. ==
B. ===
C. !=
D. =

Show Answer

Answer: B

Q99. What does NaN stand for in JavaScript?

A. Not a Number
B. New and Null
C. None Available Now
D. Numeric and Null

Show Answer

Answer: A

Q100. What feature allows using “await” outside of functions in modern JavaScript modules?

A. Async IIFE
B. Top-level await
C. Global await mode
D. Module async mode

Show Answer

Answer: B

Conclusion

Practising JavaScript MCQ and quiz questions is one of the best ways to revise concepts and get ready for interviews or coding rounds. Keep learning and exploring new questions to build confidence. You can also go through these Top 50 JavaScript Interview Questions and Answers for deeper interview preparation.

Resources and References:

Aditya Gupta
Aditya Gupta
Articles: 469
Review Your Cart
0
Add Coupon Code
Subtotal