Home | Mailing List | Blog | Tutorial Videos

Closure and Hoisting

What would be the output of the following three console.logs.

  function withVar() {
    const b = () => a;
    var a = 24;
    return b;
  }

  function withLet() {
    const b = () => a;
    let a = 24;
    return b;
  }

  function changingValue() {
    let a = 24;
    const b = () => a;
    a = 42;
    return b;
  }

  console.log(withVar()())  // ??
  console.log(withLet()())  // ??
  console.log(changingValue()())  // ??

Select one: