0

I am struggling to understand why the below code snippet returns greeting is not defined. The purpose of this question isn't how I fix it but I understand why it throws this error.

function sayHey() {
    var greeting = "Hello";
    if(greeting){
        greeting = "Hey";
       let greeting = "Hi";
        console.log(greeting);
    }
}

sayHey();
thstamod
  • 174
  • 1
  • 8

0 Answers0