HomeSubjectsUniversityBlogAbout

JavaScript Fundamentals

Topic in Web Development

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

JavaScript is a dynamically typed programming language that runs in browsers and on servers to make web pages interactive and implement application logic. Core questions contrast var, let and const in terms of scope, hoisting and the temporal dead zone. Know the primitive types, typeof results (including the quirk that typeof null returns "object"), type coercion, and the difference between == and ===. Functions are tested through declarations versus expressions, arrow functions and their lexical this, closures and callbacks. Arrays and objects come with methods such as map, filter, reduce and forEach, while DOM questions cover querySelector, addEventListener, event bubbling and delegation.

Below are 30 practice questions from a pool of 210 JavaScript Fundamentals MCQs, one of 17 topics in Web Development. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

JavaScript FundamentalsEasy

Q1. Which keyword declares a variable in JavaScript?

  1. A.variable
  2. B.var✓ Correct
  3. C.declare
  4. D.let

Explanation

The var keyword declares a variable in JavaScript.

Report an error in this question

JavaScript FundamentalsEasy

Q2. What is the correct way to write a single-line comment in JavaScript?

  1. A.<!-- comment -->
  2. B./* comment */
  3. C.// comment✓ Correct
  4. D.# comment

Explanation

Single-line comments start with //.

Report an error in this question

JavaScript FundamentalsEasy

Q3. Which operator is used for strict equality in JavaScript?

  1. A.===✓ Correct
  2. B.==
  3. C.=
  4. D.!=

Explanation

=== checks both value and type equality.

Report an error in this question

JavaScript FundamentalsEasy

Q4. What does console.log() do?

  1. A.Creates a modal dialog box on screen
  2. B.Outputs a message to the browser console✓ Correct
  3. C.Logs the user into a website account
  4. D.Creates a new log file on disk

Explanation

console.log() outputs values to the browser console for debugging.

Report an error in this question

JavaScript FundamentalsEasy

Q5. Which data type represents true or false?

  1. A.Number
  2. B.Undefined
  3. C.String
  4. D.Boolean✓ Correct

Explanation

Boolean has only two values: true and false.

Report an error in this question

JavaScript FundamentalsEasy

Q6. How do you create a function in JavaScript?

  1. A.create myFunc() {}
  2. B.def myFunc() {}
  3. C.func myFunc() {}
  4. D.function myFunc() {}✓ Correct

Explanation

Functions are declared using the function keyword.

Report an error in this question

JavaScript FundamentalsEasy

Q7. What is an array in JavaScript?

  1. A.An ordered collection of values✓ Correct
  2. B.A type of reusable function
  3. C.A single primitive value in memory
  4. D.A CSS property declaration

Explanation

An array is an ordered collection of values accessed by numeric indices.

Report an error in this question

JavaScript FundamentalsEasy

Q8. How do you write an if statement in JavaScript?

  1. A.if (x > 5) {}✓ Correct
  2. B.if x > 5 {}
  3. C.when (x > 5) {}
  4. D.if x > 5 then

Explanation

JavaScript if statements use parentheses for the condition and curly braces for the code block.

Report an error in this question

JavaScript FundamentalsEasy

Q9. Which method adds an element to the end of an array?

  1. A.add()
  2. B.insert()
  3. C.append()
  4. D.push()✓ Correct

Explanation

push() adds one or more elements to the end of an array.

Report an error in this question

JavaScript FundamentalsEasy

Q10. What does the typeof operator return?

  1. A.The CSS type selector for an HTML element
  2. B.A string indicating the data type of a value✓ Correct
  3. C.The file type extension of a source file
  4. D.The element type in an HTML document

Explanation

typeof returns a string indicating the type of the operand.

Report an error in this question

JavaScript FundamentalsMedium

Q11. What is the difference between let and var?

  1. A.var has block scope; let has function scope
  2. B.let has block scope; var has function scope✓ Correct
  3. C.They are identical in scoping behavior
  4. D.let is significantly slower in performance

Explanation

let is block-scoped, while var is function-scoped.

Report an error in this question

JavaScript FundamentalsMedium

Q12. What is a closure in JavaScript?

  1. A.A type of loop for iterating over arrays
  2. B.A built-in method to end a running program
  3. C.A method for closing the browser window
  4. D.A function accessing its outer scope variables✓ Correct

Explanation

A closure is a function that retains access to its lexical scope's variables.

Report an error in this question

JavaScript FundamentalsMedium

Q13. What is the purpose of the 'this' keyword?

  1. A.Refers to the previously declared variable value
  2. B.Refers to the current CSS style being applied
  3. C.Refers to the object executing current function✓ Correct
  4. D.Creates a new object instance in current scope

Explanation

'this' refers to the object context in which the current function is executing.

Report an error in this question

JavaScript FundamentalsMedium

Q14. What is hoisting in JavaScript?

  1. A.Moving declarations to the top of their scope✓ Correct
  2. B.Uploading files from the client to the server
  3. C.Raising and throwing runtime error exceptions
  4. D.Lifting DOM elements higher in the page layout

Explanation

Hoisting moves declarations to the top of their scope before execution.

Report an error in this question

JavaScript FundamentalsMedium

Q15. What is the difference between null and undefined?

  1. A.undefined always indicates a runtime error occurred
  2. B.They are identical in meaning and behavior
  3. C.null is intentional absence; undefined means not assigned✓ Correct
  4. D.null is for numbers; undefined is for string values

Explanation

null is explicitly assigned to indicate no value, while undefined means not yet assigned.

Report an error in this question

JavaScript FundamentalsMedium

Q16. What does the map() method do on an array?

  1. A.Creates a geographic map data visualization
  2. B.Sorts the array elements in ascending order
  3. C.Creates a new array by applying a function to each item✓ Correct
  4. D.Maps array indices to their corresponding values

Explanation

map() creates a new array by calling a function on every element.

Report an error in this question

JavaScript FundamentalsMedium

Q17. What is event bubbling in JavaScript?

  1. A.A CSS animation effect using keyframe transitions
  2. B.A memory leak issue caused by circular references
  3. C.Creating animated bubble visual effects on screen
  4. D.When an event on a child propagates up through parents✓ Correct

Explanation

Event bubbling means an event propagates from the target element up through its ancestors.

Report an error in this question

JavaScript FundamentalsMedium

Q18. What is the purpose of JSON.parse()?

  1. A.Compresses JSON data to reduce its file size
  2. B.Creates a new JSON file on the server disk
  3. C.Converts a JSON string into a JavaScript object✓ Correct
  4. D.Validates JSON syntax for correctness and errors

Explanation

JSON.parse() transforms a JSON string into a JavaScript object.

Report an error in this question

JavaScript FundamentalsMedium

Q19. What is template literal syntax in JavaScript?

  1. A.Using single quotes around string literals
  2. B.Using double quotes around string values
  3. C.Using the + operator for concatenation
  4. D.Using backticks with ${} for interpolation✓ Correct

Explanation

Template literals use backticks and ${expression} syntax to embed expressions in strings.

Report an error in this question

JavaScript FundamentalsMedium

Q20. What is destructuring in JavaScript?

  1. A.Permanently deleting JavaScript objects from memory
  2. B.Unpacking values from arrays or objects into variables✓ Correct
  3. C.Breaking code into smaller modules and files
  4. D.Removing DOM elements from the document tree

Explanation

Destructuring extracts values from arrays or objects into separate variables.

Report an error in this question

JavaScript FundamentalsHard

Q21. What is the event loop in JavaScript?

  1. A.A mechanism handling async callbacks via call stack✓ Correct
  2. B.An event listener looping through all DOM elements
  3. C.A standard for loop iterating over event arrays
  4. D.A DOM traversal method for walking element tree

Explanation

The event loop checks the call stack and pushes callbacks from the task queue.

Report an error in this question

JavaScript FundamentalsHard

Q22. What is the difference between == and === in terms of type coercion?

  1. A.Both operators perform type coercion
  2. B.Neither operator performs type coercion
  3. C.== performs type coercion; === does not✓ Correct
  4. D.=== performs type coercion; == does not

Explanation

== converts operands to the same type before comparing, while === requires both type and value to match.

Report an error in this question

JavaScript FundamentalsHard

Q23. What is the Temporal Dead Zone (TDZ)?

  1. A.A time-related API for scheduling delayed operations
  2. B.A concept related to memory management and GC
  3. C.A garbage collection phase reclaiming unused memory
  4. D.The period between scope entry and let/const declaration✓ Correct

Explanation

The TDZ is the period from the start of a block until the let/const declaration is reached.

Report an error in this question

JavaScript FundamentalsHard

Q24. What is the difference between call(), apply(), and bind()?

  1. A.Only bind invokes the function immediately when called
  2. B.call and apply invoke immediately; bind returns a new function✓ Correct
  3. C.They are all identical in functionality
  4. D.call is for arrays; apply is for objects arguments

Explanation

call() takes individual arguments, apply() takes an array, and bind() returns a new function.

Report an error in this question

JavaScript FundamentalsHard

Q25. What is a WeakMap in JavaScript?

  1. A.A collection with weakly referenced object keys for GC✓ Correct
  2. B.A smaller and more limited version of Map class
  3. C.A map collection with weak security encryption
  4. D.A map storing only string keys and string values

Explanation

WeakMap holds weak references to object keys, allowing garbage collection.

Report an error in this question

JavaScript FundamentalsHard

Q26. What is the prototype chain in JavaScript?

  1. A.A CSS inheritance model for cascading styles
  2. B.The mechanism objects use to inherit properties✓ Correct
  3. C.A linked list data structure for sequential data
  4. D.A blockchain implementation for distributed apps

Explanation

The prototype chain links objects together for property lookup inheritance.

Report an error in this question

JavaScript FundamentalsHard

Q27. What is tail call optimization in JavaScript?

  1. A.A DOM rendering optimization for reducing paint operations
  2. B.A CSS optimization technique for faster style calculations
  3. C.Optimizing the last element of an array for access
  4. D.Reusing the stack frame for a function call in tail position✓ Correct

Explanation

Tail call optimization reuses the current stack frame for function calls in tail position.

Report an error in this question

JavaScript FundamentalsHard

Q28. What is the difference between Object.freeze() and Object.seal()?

  1. A.freeze prevents all changes; seal allows modifying values✓ Correct
  2. B.freeze only prevents deletion of properties
  3. C.seal prevents all changes including modifications
  4. D.They are identical in behavior on objects

Explanation

Object.freeze() makes an object fully immutable, while Object.seal() prevents adding/removing but allows modification.

Report an error in this question

JavaScript FundamentalsHard

Q29. What is a Symbol in JavaScript?

  1. A.A unique immutable primitive for property identifiers✓ Correct
  2. B.A string formatting token for template processing
  3. C.A CSS icon or symbol for decorative elements
  4. D.A mathematical operator for advanced calculations

Explanation

Symbol creates a unique, immutable primitive value for non-colliding property keys.

Report an error in this question

JavaScript FundamentalsHard

Q30. What is the purpose of generator functions?

  1. A.To generate HTML markup from template files
  2. B.To create iterators that pause and resume via yield✓ Correct
  3. C.To create class instances from constructor functions
  4. D.To generate random numbers for cryptographic use

Explanation

Generator functions (function*) produce iterators that can pause with yield and resume later.

Report an error in this question

Ready to test yourself on JavaScript Fundamentals?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start JavaScript Fundamentals Quiz