JavaScript

Practice JavaScript MCQs covering variables, data types, operators, functions, objects, arrays, DOM manipulation, events, ES6+, asynchronous programming, APIs, and modern JavaScript concepts.

3
Topics
304
Total MCQs

JavaScript

Practice JavaScript MCQs covering variables, data types, operators, functions, objects, arrays, DOM manipulation, events, ES6+, asynchronous programming, APIs, and modern JavaScript concepts.

105 MCQs Page 1 of 6
0
0
/ 105
0%
A. A scripting language
B. A markup language
C. A database
D. An operating system
Answer: JavaScript is a high-level, interpreted scripting language.
A. var
B. let
C. const
D. All of the above
Answer: var, let, and const are all used to declare variables in JavaScript.
A. null
B. undefined
C. object
D. number
Answer: typeof null returns 'object' due to a historical bug in JavaScript.
A. JSON.stringify()
B. JSON.parse()
C. JSON.convert()
D. JSON.toObject()
Answer: JSON.parse() is used to parse a JSON string and create a JavaScript object.
A. ==
B. ===
C. =
D. !==
Answer: === is the strict equality operator, checking both value and type.
A. push()
B. pop()
C. shift()
D. unshift()
Answer: push() appends elements to the end of an array and returns the new length.
A. true
B. false
C. undefined
D. NaN
Answer: Due to floating-point precision, 0.1 + 0.2 does not exactly equal 0.3.
A. String
B. Number
C. Float
D. Boolean
Answer: JavaScript has Number type, not Float. All numbers are floating-point.
A. Refers to the current object
B. Refers to the global object
C. Refers to the parent object
D. All of the above depending on context
Answer: The value of 'this' depends on how a function is called (execution context).
A. push()
B. pop()
C. shift()
D. slice()
Answer: pop() removes and returns the last element of an array.
A. <!-- comment -->
B. // comment
C. /* comment */
D. Both b and c
Answer: Both // for single-line and /* */ for multi-line comments are valid.
A. class
B. function
C. object
D. new
Answer: The 'class' keyword is used to define a class in ES6.
A. array
B. object
C. undefined
D. null
Answer: Arrays are of type 'object' in JavaScript.
A. length()
B. len()
C. size()
D. length
Answer: String length is accessed via the .length property, not a method.
A. 4
B. 22
C. NaN
D. TypeError
Answer: When a number and string are added, the number is coerced to a string and concatenated.
A. JSON.parse()
B. JSON.stringify()
C. JSON.convert()
D. JSON.toJSON()
Answer: JSON.stringify() converts a JavaScript object to a JSON string.
A. false
B. true
C. undefined
D. NaN
Answer: !! converts a value to a boolean. Any non-empty string is truthy, so !!'false' is true.
A. Object.create()
B. new Object()
C. {}
D. All of the above
Answer: All three methods are valid ways to create objects in JavaScript.
A. Creates a new function with a specific this value
B. Binds an event to an element
C. Binds two objects together
D. None of the above
Answer: bind() creates a new function with a specified 'this' context and optional arguments.
A. 10
B. 11
C. 1
D. NaN
Answer: 1 + '1' results in '11', then '11' - 1 results in 10 (string coerced to number).
1 2 3