$ cd ../ (all courses)

JavaScript

The language of the web. Runs everywhere.

⚠ pattern-based checks (code is analyzed, not compiled)

About JavaScript

JavaScript powers every browser on the planet, plus Node.js on servers. It's dynamically typed, prototype-based, and incredibly flexible. NOTE: In this course, your code is checked by analyzing what you wrote (pattern matching). It is NOT actually executed. Focus on writing correct, idiomatic JavaScript.

Quick-reference cheat sheet
// JavaScript cheat-sheet
// Single-line comment
/* multi-line */

let x = 10;             // mutable
const PI = 3.14;        // immutable binding
var legacy = 1;         // avoid in modern code

// Strings
const name = "ada";
const greet = `Hello, ${name}!`;   // template literal

// Arrays / objects
const nums = [1, 2, 3];
nums.push(4);
const person = { name: "ada", age: 36 };

// Conditions
if (x > 0) {
  console.log("positive");
} else if (x === 0) {
  console.log("zero");
} else {
  console.log("negative");
}

// Loops
for (let i = 0; i < 5; i++) console.log(i);
for (const n of nums) console.log(n);

// Functions
function add(a, b) { return a + b; }
const mul = (a, b) => a * b;

// Higher-order
nums.map(n => n * 2);
nums.filter(n => n > 1);
nums.reduce((a, b) => a + b, 0);

// Destructuring & spread
const { name: n1 } = person;
const more = [...nums, 5, 6];

// Classes
class Animal {
  constructor(name) { this.name = name; }
  greet() { return `hi, ${this.name}`; }
}

Tasks

  1. 01
    Hello, World!
    Use console.log to print a greeting.
    intro
  2. 02
    let and const
    Declare a const PI and a let counter.
    intro
  3. 03
    String concatenation
    Concatenate two strings with +.
    intro
  4. 04
    if / else
    Branch on a number.
    intro
  5. 05
    Arrow function: add
    Define an arrow function add(a, b) that returns the sum.
    easy
  6. 06
    Template literals
    Build a greeting using backtick template literals.
    easy
  7. 07
    for loop 1..10
    console.log numbers 1 through 10.
    easy
  8. 08
    while loop
    Count down from 5 to 1 with a while loop.
    easy
  9. 09
    Array push
    Build an array with .push.
    easy
  10. 10
    Double with .map
    Use .map() to double every number in an array.
    easy
  11. 11
    Filter evens
    Use .filter() to keep only even numbers.
    medium
  12. 12
    Sum with reduce
    Use .reduce() to sum an array.
    medium
  13. 13
    Array .find
    Find the first user older than 30.
    medium
  14. 14
    Destructuring
    Destructure name and age from an object.
    medium
  15. 15
    Spread operator
    Combine two arrays with spread.
    medium
  16. 16
    Object shorthand
    Use shorthand to build an object.
    medium
  17. 17
    Ternary expression
    Pick a label using ternary.
    medium
  18. 18
    Define a class
    Class Animal with a constructor and a method.
    medium
  19. 19
    Extending a class
    Subclass Animal with Dog.
    hard
  20. 20
    JSON.stringify
    Serialize an object to JSON.
    medium
  21. 21
    Set: unique values
    Use Set to dedupe an array.
    medium
  22. 22
    Map collection
    Build a Map and set entries.
    medium
  23. 23
    Regex test
    Test if string matches a digit pattern.
    medium
  24. 24
    Promise chain
    Create a Promise that resolves to 42, then log it doubled.
    hard
  25. 25
    async/await
    Write an async function that awaits a Promise.
    hard
  26. 26
    try / catch
    Wrap JSON.parse in try/catch.
    hard
  27. 27
    Closures: counter
    Make a counter factory using closures.
    hard
  28. 28
    fetch API
    Fetch JSON and return its parsed body.
    hard
  29. 29
    Generator function
    Define a generator yielding 1, 2, 3.
    hard
  30. 30
    Debounce utility
    Implement a debounce helper.
    hard
  31. 31
    Multi-line template literal
    Use backticks with newlines and ${}.
    easy
  32. 32
    Strict vs loose equality
    Use === instead of ==.
    easy
  33. 33
    Arrow function shorthand
    Single-expression arrow.
    easy
  34. 34
    Default parameters
    Function with a default arg.
    easy
  35. 35
    Rest + spread
    Sum any number of args.
    medium
  36. 36
    Object destructuring + rename
    Destructure with alias.
    medium
  37. 37
    Array destructure + skip
    Skip middle element.
    medium
  38. 38
    Optional chaining + nullish
    ?. and ?? together.
    medium
  39. 39
    Array.find
    Get the first match.
    medium
  40. 40
    every & some
    All positive? Any negative?
    medium
  41. 41
    Array.flatMap
    Split sentences into words.
    medium
  42. 42
    Set: unique values
    Dedupe an array via Set.
    medium
  43. 43
    Map collection
    Use Map with .set and .get.
    medium
  44. 44
    Object.entries loop
    Iterate key/value with for...of.
    medium
  45. 45
    JSON parse + stringify
    Roundtrip an object.
    medium
  46. 46
    Class with getter
    Define a get accessor.
    hard
  47. 47
    Class extends + super
    Subclass with super().
    hard
  48. 48
    Private class field
    Use #field syntax.
    hard
  49. 49
    new Promise
    Wrap a setTimeout in a Promise.
    hard
  50. 50
    async / await + try
    Await with error handling.
    hard
  51. 51
    Promise.all
    Wait for parallel promises.
    hard
  52. 52
    Generator function
    function* with yield.
    hard
  53. 53
    Iterable via Symbol.iterator
    Custom iterable object.
    hard
  54. 54
    Closure: makeCounter
    Return functions sharing state.
    hard
  55. 55
    Throttle utility
    Limit calls to once per ms.
    hard
  56. 56
    Currying
    Curry a 3-arg function.
    hard
  57. 57
    structuredClone deep copy
    Clone a nested object.
    hard
  58. 58
    Regex named groups
    Match a date with (?<year>...).
    hard
  59. 59
    Proxy interception
    Trap property access with Proxy.
    hard
  60. 60
    Modulo: check even
    Use % to log whether 14 is even.
    easy
  61. 61
    String length
    Log the length of a string.
    easy
  62. 62
    Uppercase a string
    Convert a string to UPPERCASE.
    easy
  63. 63
    String.includes
    Check if a string contains a substring.
    easy
  64. 64
    Slice a substring
    Extract characters with .slice.
    easy
  65. 65
    Split a CSV line
    Split a comma-separated string into an array.
    easy
  66. 66
    Array.join with separator
    Join words with dashes.
    medium
  67. 67
    Sort numbers ascending
    Sort with a comparator (default sort is lexicographic!).
    medium
  68. 68
    Array.from a range
    Build [1,2,3,4,5] with Array.from.
    medium
  69. 69
    Roll a die (1–6)
    Generate a random integer 1–6.
    medium
  70. 70
    Object.keys
    Get the keys of an object as an array.
    medium
  71. 71
    Loop with Object.entries
    Iterate key/value pairs with for...of and Object.entries.
    medium
  72. 72
    Nullish coalescing (??)
    Default only when null/undefined (not 0 or '').
    medium
  73. 73
    Logical OR assignment (||=)
    Assign only if the current value is falsy.
    medium
  74. 74
    String.replaceAll
    Replace every occurrence of a substring.
    medium
  75. 75
    Tagged template literal
    Define a tag function that uppercases interpolated values.
    hard
  76. 76
    Promise.allSettled
    Await all promises, including the rejected ones.
    hard
  77. 77
    Promise.race for timeouts
    Race a real promise against a timeout rejection.
    hard
  78. 78
    for await...of an async iterable
    Consume an async generator with for await...of.
    hard
  79. 79
    WeakMap as a private cache
    Cache per-object data without leaking memory.
    hard
  80. 80
    Recursive deep flatten
    Flatten any-depth nested array WITHOUT using .flat(Infinity).
    hard
  81. 81
    Memoize an expensive function
    Cache results of pure function calls in a closure + Map.
    hard
  82. 82
    Capstone: TodoList class
    Build a TodoList class with add / toggle / remove / filter (active|done|all).
    hard