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.
Answer: JavaScript is a high-level, interpreted scripting language.
Answer: var, let, and const are all used to declare variables in JavaScript.
Answer: typeof null returns 'object' due to a historical bug in JavaScript.
Answer: JSON.parse() is used to parse a JSON string and create a JavaScript object.
Answer: === is the strict equality operator, checking both value and type.
Answer: push() appends elements to the end of an array and returns the new length.
Answer: Due to floating-point precision, 0.1 + 0.2 does not exactly equal 0.3.
Answer: JavaScript has Number type, not Float. All numbers are floating-point.
Answer: The value of 'this' depends on how a function is called (execution context).
Answer: pop() removes and returns the last element of an array.
Answer: Both // for single-line and /* */ for multi-line comments are valid.
Answer: The 'class' keyword is used to define a class in ES6.
Answer: Arrays are of type 'object' in JavaScript.
Answer: String length is accessed via the .length property, not a method.
Answer: When a number and string are added, the number is coerced to a string and concatenated.
Answer: JSON.stringify() converts a JavaScript object to a JSON string.
Answer: !! converts a value to a boolean. Any non-empty string is truthy, so !!'false' is true.
Answer: All three methods are valid ways to create objects in JavaScript.
Answer: bind() creates a new function with a specified 'this' context and optional arguments.
Answer: 1 + '1' results in '11', then '11' - 1 results in 10 (string coerced to number).