Block Scope II

I don’t understand the example exercise:

const colorOfSky = () => {
  const dusk = true;
  let color = 'blue'; 
  if (dusk) {
    let color = 'pink';
    console.log(color); // pink
  console.log(color); // blue 

colorOfSky(); // blue
console.log(color); // ReferenceError

I don’t understand why when we call the function in the result it doesn’t show pink and blue? I see dusk is true so why just blue appears when we call it? Why pink it’s not showing?

Thanks so much!

it shows pink and blue, i ran your code here:,console

there is a run button in top right corner, it runs fine?

functions only executed when called

Thank you. The code above was took from the lesson. Maybe you should update it in there so the explanation would be correct.
I thought I had it wrong, thinking that the 2 colors should appear. Thank you, again.

in my case, two colors do appear. Please provide a screenshot for clarification.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.