Skip to content
📜

JavaScript Basics

150 exercises

Practice exercises for JavaScript.

  1. 1

    Let vs Const Quiz

    Test your understanding of what happens when you reassign a const variable in JavaScript.

    Multiple Choice Easy
  2. 2

    Predict Variable Reassignment

    Predict the output of a JavaScript program that reassigns a let variable.

    Predict Output Beginner
  3. 3

    Declare a JavaScript Constant

    Practice using the const keyword to declare a constant variable in JavaScript.

    Fill in the Blank Beginner
  4. 4

    JavaScript Primitive Types

    Check your understanding of which types are primitives in JavaScript.

    Concept Check Medium
  5. 5

    Find the Arrow Function Error

    Spot a common syntax error in a JavaScript arrow function declaration.

    Find the Mistake Easy
  6. 6

    Predict the Function Call Result

    Predict the output of a simple JavaScript function call with a numeric argument.

    Predict Output Beginner
  7. 7

    JavaScript Array length Quiz

    Test your understanding of the length property on a JavaScript array.

    Multiple Choice Beginner
  8. 8

    Predict Array push Output

    Predict the new length of a JavaScript array after calling push.

    Predict Output Beginner
  9. 9

    JavaScript Object Keys Quiz

    Test your understanding of how object keys work in JavaScript.

    Multiple Choice Beginner
  10. 10

    Predict Object Property Access

    Predict the value returned by accessing a property on a JavaScript object.

    Predict Output Beginner
  11. 11

    Predict JavaScript if/else Output

    Predict the output of a JavaScript if/else statement with a comparison.

    Predict Output Beginner
  12. 12

    Complete the if Condition

    Fill in the blank to make the if condition true when temperature is above 30.

    Fill in the Blank Beginner
  13. 13

    Predict JavaScript while Loop Output

    Predict the output of a JavaScript while loop that counts down.

    Predict Output Beginner
  14. 14

    Spot the Infinite Loop

    Identify a common mistake that causes a JavaScript while loop to run forever.

    Find the Mistake Easy
  15. 15

    What Is the DOM?

    Check your conceptual understanding of what the DOM is in web development.

    Concept Check Medium
  16. 16

    querySelector Quiz

    Test your knowledge of the querySelector method for selecting DOM elements.

    Multiple Choice Medium
  17. 17

    What Is a Promise?

    Check your conceptual understanding of what a Promise is in JavaScript.

    Concept Check Medium
  18. 18

    async/await Keyword Quiz

    Test your knowledge of the async and await keywords in modern JavaScript.

    Multiple Choice Medium
  19. 19

    var vs let Scope Quiz

    Test your understanding of how var and let differ in scoping within a block.

    Multiple Choice Easy
  20. 20

    Predict var Hoisting

    Predict the output of code that uses a var variable before its declaration.

    Predict Output Medium
  21. 21

    Declare a let Variable

    Fill in the blank to declare a mutable variable in JavaScript.

    Fill in the Blank Beginner
  22. 22

    Spot the const Reassignment Error

    Find the mistake in code that tries to reassign a const variable.

    Find the Mistake Easy
  23. 23

    var, let, const Concept Check

    Check your understanding of the differences between var, let, and const.

    Concept Check Medium
  24. 24

    Temporal Dead Zone Quiz

    Test your knowledge of the temporal dead zone with let and const.

    Multiple Choice Medium
  25. 25

    Predict typeof Results

    Predict the output of several typeof checks in JavaScript.

    Predict Output Easy
  26. 26

    String Concatenation Quiz

    Test your understanding of string concatenation with the + operator.

    Multiple Choice Beginner
  27. 27

    Check Type with typeof

    Fill in the blank to check if a value is a number.

    Fill in the Blank Beginner
  28. 28

    Strict vs Loose Equality

    Check your understanding of == vs === in JavaScript.

    Concept Check Medium
  29. 29

    Predict Type Coercion

    Predict the output of JavaScript type coercion in comparisons.

    Predict Output Medium
  30. 30

    Spot the Loose Equality Bug

    Find the bug caused by using loose equality (==) instead of strict (===).

    Find the Mistake Easy
  31. 31

    Function Declaration vs Expression

    Test your knowledge of function declarations vs function expressions.

    Multiple Choice Medium
  32. 32

    Predict Default Parameters

    Predict the output of a function using default parameters.

    Predict Output Easy
  33. 33

    Write an Arrow Function

    Fill in the blank to complete an arrow function that squares a number.

    Fill in the Blank Beginner
  34. 34

    Spot the Missing Return

    Find the bug in a function that uses curly braces but forgets to return.

    Find the Mistake Easy
  35. 35

    Closure Concept Check

    Check your understanding of closures in JavaScript.

    Concept Check Medium
  36. 36

    Predict Closure Output

    Predict the output of a closure that captures a counter variable.

    Predict Output Medium
  37. 37

    Rest Parameters Quiz

    Test your understanding of rest parameters in JavaScript functions.

    Multiple Choice Medium
  38. 38

    Predict Callback Execution

    Predict the output of a function that accepts a callback.

    Predict Output Easy
  39. 39

    Array map vs forEach Quiz

    Test your understanding of the difference between map and forEach.

    Multiple Choice Medium
  40. 40

    Predict Array map Output

    Predict the result of mapping over an array with a transformation.

    Predict Output Easy
  41. 41

    Predict Array filter Output

    Predict the result of filtering an array with a predicate.

    Predict Output Easy
  42. 42

    Predict Array reduce Output

    Predict the result of reducing an array to a single value.

    Predict Output Medium
  43. 43

    Array Destructuring Fill

    Fill in the blank to destructure the first two elements of an array.

    Fill in the Blank Easy
  44. 44

    Spot splice vs slice Mistake

    Find the mistake in code that confuses splice with slice.

    Find the Mistake Medium
  45. 45

    Array Reference Concept

    Check your understanding of array reference semantics in JavaScript.

    Concept Check Medium
  46. 46

    Array indexOf Quiz

    Test your knowledge of the indexOf method on arrays.

    Multiple Choice Easy
  47. 47

    Predict Spread Operator

    Predict the output of using the spread operator to combine arrays.

    Predict Output Easy
  48. 48

    Array find Fill

    Fill in the blank to find the first element greater than 10.

    Fill in the Blank Easy
  49. 49

    Object Methods Quiz

    Test your understanding of method shorthand syntax in objects.

    Multiple Choice Easy
  50. 50

    Predict Object Destructuring

    Predict the output of object destructuring with renamed properties.

    Predict Output Easy
  51. 51

    Computed Property Fill

    Fill in the blank to use a variable as an object key.

    Fill in the Blank Medium
  52. 52

    Spot the this Binding Mistake

    Find the bug where `this` loses its binding when a method is extracted.

    Find the Mistake Medium
  53. 53

    Prototype Concept Check

    Check your understanding of the prototype chain in JavaScript.

    Concept Check Medium
  54. 54

    Predict Object.keys Output

    Predict the output of Object.keys on an object.

    Predict Output Easy
  55. 55

    Object Spread Quiz

    Test your understanding of the spread operator with objects.

    Multiple Choice Medium
  56. 56

    Predict Nested Object Access

    Predict the output of accessing a nested object property.

    Predict Output Easy
  57. 57

    Predict Ternary Output

    Predict the output of a ternary conditional expression.

    Predict Output Easy
  58. 58

    Switch Statement Quiz

    Test your knowledge of switch statement fall-through behavior.

    Multiple Choice Medium
  59. 59

    Complete the Comparison

    Fill in the blank to check if a value is neither null nor undefined.

    Fill in the Blank Easy
  60. 60

    Spot the Assignment in if

    Find the bug where = is used instead of == in an if condition.

    Find the Mistake Easy
  61. 61

    Predict for Loop Output

    Predict the output of a standard for loop that sums numbers.

    Predict Output Easy
  62. 62

    Predict for...of Output

    Predict the output of a for...of loop over an array.

    Predict Output Easy
  63. 63

    for...in vs for...of Quiz

    Test your understanding of the difference between for...in and for...of.

    Multiple Choice Medium
  64. 64

    Complete the while Loop

    Fill in the blank to make a while loop run exactly 3 times.

    Fill in the Blank Easy
  65. 65

    Spot the Off-by-One Error

    Find the off-by-one bug in a loop that processes an array.

    Find the Mistake Easy
  66. 66

    break vs continue Concept

    Check your understanding of break and continue in loops.

    Concept Check Easy
  67. 67

    getElementById Quiz

    Test your knowledge of the getElementById DOM method.

    Multiple Choice Easy
  68. 68

    Predict textContent Update

    Predict what happens when textContent is set on a DOM element.

    Predict Output Easy
  69. 69

    Complete addEventListener

    Fill in the blank to attach a click event listener to a button.

    Fill in the Blank Easy
  70. 70

    Spot innerHTML vs textContent Issue

    Find the security issue with using innerHTML for user input.

    Find the Mistake Medium
  71. 71

    Event Bubbling Concept

    Check your understanding of event bubbling in the DOM.

    Concept Check Medium
  72. 72

    classList Quiz

    Test your knowledge of the classList API for managing CSS classes.

    Multiple Choice Easy
  73. 73

    Predict Promise.then Chain

    Predict the output of a Promise.then chain.

    Predict Output Medium
  74. 74

    Promise.all Quiz

    Test your understanding of Promise.all behavior.

    Multiple Choice Medium
  75. 75

    Microtask Concept Check

    Check your understanding of microtasks and the event loop.

    Concept Check Medium
  76. 76

    Predict async/await Output

    Predict the output of an async function using await.

    Predict Output Medium
  77. 77

    Spot the Unhandled Rejection

    Find the bug where a Promise rejection is not caught.

    Find the Mistake Medium
  78. 78

    Complete try/catch for async

    Fill in the blank to catch errors from an async operation.

    Fill in the Blank Medium
  79. 79

    Predict Template Literal

    Predict the output of a template literal with embedded expressions.

    Predict Output Easy
  80. 80

    Destructuring with Default Quiz

    Test your knowledge of destructuring with default values.

    Multiple Choice Medium
  81. 81

    Spread to Copy Array

    Fill in the blank to create a shallow copy of an array using spread.

    Fill in the Blank Easy
  82. 82

    Class Concept Check

    Check your understanding of ES6 class syntax.

    Concept Check Medium
  83. 83

    Predict Generator Output

    Predict the output of a generator function.

    Predict Output Medium
  84. 84

    Symbol Uniqueness Quiz

    Test your understanding of Symbol uniqueness.

    Multiple Choice Medium
  85. 85

    Spot Map vs Object Mistake

    Find the issue with using a plain object when a Map would be better.

    Find the Mistake Medium
  86. 86

    Set Concept Check

    Check your understanding of the Set data structure.

    Concept Check Easy
  87. 87

    Predict JSON.parse Output

    Predict the output of parsing a JSON string.

    Predict Output Easy
  88. 88

    Error Handling Quiz

    Test your knowledge of try/catch/finally behavior.

    Multiple Choice Medium
  89. 89

    localStorage Fill

    Fill in the blank to save a value to localStorage.

    Fill in the Blank Easy
  90. 90

    Spot parseInt Radix Issue

    Find the bug with parseInt when the string starts with 0.

    Find the Mistake Medium
  91. 91

    Hoisting Concept Check

    Check your understanding of hoisting in JavaScript.

    Concept Check Medium
  92. 92

    Predict Coercion in Conditions

    Predict which values are truthy and which are falsy.

    Predict Output Medium
  93. 93

    String Methods Quiz

    Test your knowledge of common string methods.

    Multiple Choice Easy
  94. 94

    Predict Array sort Output

    Predict the output of sorting a numeric array without a comparator.

    Predict Output Medium
  95. 95

    Regex Test Fill

    Fill in the blank to test if a string matches a digit pattern.

    Fill in the Blank Medium
  96. 96

    Spot Floating Point Precision

    Find the issue with floating point arithmetic in JavaScript.

    Find the Mistake Medium
  97. 97

    Pass by Reference Concept

    Check your understanding of pass-by-reference for objects.

    Concept Check Medium
  98. 98

    Predict Bitwise Operation

    Predict the output of a bitwise operation.

    Predict Output Medium
  99. 99

    Date Object Quiz

    Test your knowledge of the JavaScript Date object.

    Multiple Choice Easy
  100. 100

    Event Loop Concept Check

    Check your understanding of the JavaScript event loop.

    Concept Check Medium
  101. 101

    Let vs Const

    Which keyword declares a variable that cannot be reassigned?

    Multiple Choice Beginner
  102. 102

    Typeof Array

    What does typeof [] return?

    Multiple Choice Beginner
  103. 103

    Array Length After Pop

    After [1,2,3].pop(), what is the array length?

    Multiple Choice Beginner
  104. 104

    String Split Result

    What does "a,b,c".split(",") return?

    Multiple Choice Easy
  105. 105

    Object Keys Method

    What does Object.keys({a:1,b:2}) return?

    Multiple Choice Easy
  106. 106

    Promise State

    Which is NOT a valid Promise state?

    Multiple Choice Medium
  107. 107

    Var Function Scope

    Where is a var variable accessible?

    Multiple Choice Medium
  108. 108

    Array Map Return

    What does [1,2].map(x => x*2) return?

    Multiple Choice Easy
  109. 109

    Strict Equality Result

    What does 0 === "" return?

    Multiple Choice Beginner
  110. 110

    For...of vs For...in

    Which loop iterates over array values (not indices)?

    Multiple Choice Easy
  111. 111

    Async Await Result

    What does await do inside an async function?

    Multiple Choice Medium
  112. 112

    Array Reduce Sum

    What does [1,2,3].reduce((a,b) => a+b, 0) return?

    Multiple Choice Medium
  113. 113

    Object Shallow Copy

    What does Object.assign({}, obj) create?

    Multiple Choice Medium
  114. 114

    Closure Variable Capture

    In a closure, when is the outer variable accessed?

    Multiple Choice Medium
  115. 115

    Event Loop Nature

    What does the JavaScript event loop do?

    Multiple Choice Medium
  116. 116

    Array Sort Default

    What does [10,2,1].sort() return?

    Multiple Choice Medium
  117. 117

    Template Literal Multi-line

    Can template literals span multiple lines?

    Multiple Choice Easy
  118. 118

    JSON Undefined Handling

    What happens to undefined properties in JSON.stringify?

    Multiple Choice Medium
  119. 119

    Array Destructuring Swap

    Can you swap variables with [a, b] = [b, a]?

    Multiple Choice Easy
  120. 120

    SetTimeout Minimum Delay

    What is the minimum delay for setTimeout in browsers?

    Multiple Choice Medium
  121. 121

    Object Property Shorthand

    What does { x, y } mean when x=1, y=2?

    Multiple Choice Easy
  122. 122

    Array Includes Method

    What does [1,2,3].includes(2) return?

    Multiple Choice Beginner
  123. 123

    Optional Chaining Result

    What does null?.x return?

    Multiple Choice Easy
  124. 124

    Promise All Behavior

    What happens if one Promise in Promise.all rejects?

    Multiple Choice Medium
  125. 125

    Number IsInteger

    What does Number.isInteger(3.0) return?

    Multiple Choice Easy
  126. 126

    Array Flat Method

    What does [1,[2,[3]]].flat() return?

    Multiple Choice Medium
  127. 127

    String Includes

    What does "hello world".includes("world") return?

    Multiple Choice Beginner
  128. 128

    Rest Parameters

    What does function f(...args) { return args; } give for f(1,2,3)?

    Multiple Choice Easy
  129. 129

    Symbol Unique

    What does Symbol() === Symbol() return?

    Multiple Choice Medium
  130. 130

    Generator Function

    What does a generator function return?

    Multiple Choice Medium
  131. 131

    Array Push Length

    Predict the output.

    Predict Output Beginner
  132. 132

    Object Access

    Predict the output.

    Predict Output Beginner
  133. 133

    Ternary Result

    Predict the output.

    Predict Output Beginner
  134. 134

    Loop Count

    Predict the output.

    Predict Output Easy
  135. 135

    Array Join

    Predict the output.

    Predict Output Easy
  136. 136

    String Repeat

    Predict the output.

    Predict Output Easy
  137. 137

    Object Spread

    Predict the output.

    Predict Output Easy
  138. 138

    Array Filter Count

    Predict the output.

    Predict Output Easy
  139. 139

    Math Max

    Predict the output.

    Predict Output Easy
  140. 140

    Typeof Function

    Predict the output.

    Predict Output Beginner
  141. 141

    Array Find

    Predict the output.

    Predict Output Easy
  142. 142

    String Slice

    Predict the output.

    Predict Output Easy
  143. 143

    Object Entries

    Predict the output.

    Predict Output Medium
  144. 144

    Promise Resolve

    Predict the output.

    Predict Output Medium
  145. 145

    Array Concat

    Predict the output.

    Predict Output Easy
  146. 146

    Nested Object Access

    Predict the output.

    Predict Output Medium
  147. 147

    Array IndexOf

    Predict the output.

    Predict Output Easy
  148. 148

    Boolean Coercion

    Predict the output.

    Predict Output Medium
  149. 149

    Array Reverse

    Predict the output.

    Predict Output Easy
  150. 150

    String CharAt

    Predict the output.

    Predict Output Beginner

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects