Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 509 Bytes

38.Hoisting-IV.md

File metadata and controls

45 lines (34 loc) · 509 Bytes

38. Hoisting IV

Problem

https://bigfrontend.dev/quiz/Hoisting-IV

Problem Description

What does the code snippet below output by console.log?

let foo = 10;
function func1() {
  console.log(foo);
  var foo = 1;
}
func1();

function func2() {
  console.log(foo);
  let foo = 1;
}
func2();

Answer

let foo = 10;
function func1() {
  console.log(foo); // undefined
  var foo = 1;
}
func1();

function func2() {
  console.log(foo); // Error
  let foo = 1;
}
func2();