Scope/Block Scope II why on earth the function without "return" returns a value?

I am referring to the example on that page:

The example is like that:

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); // undefined

Why on earth the function colorOfSky is supposed to return “blue” while it has no “return” inside and basically no idea what is its result?

color is a local variable and not visible outside of the function.

That’s pretty clear. But why then blue in the comment?

 colorOfSky(); // blue

Because the function is logging the value. No return value needed since the task is completed by the function.

That’s it. I have been confused by the comment //blue - thought it is about colorOfSky() function, in fact it is about color variable. Now clear, thanks

1 Like

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