I am having doubt in following code how const is working. below code runs without error and showing Z is 8 . what my expectation is it should throw refrence error z is already defined . Can anyone explain this
(function() {
  {
    const z = 4;
    if (true) {
      const z = 8;
      console.log("Z is " + z);
    }
  }
})() 
     
    