0

function show() {
  return value;
}

let value = 1000


console.log(show());

I guess let is the local variable but I don't understand why this coding returns 1000

I thought an message would appear

value is not defined

Harun Yilmaz
  • 8,281
  • 3
  • 24
  • 35
Jinsu
  • 19
  • 6

1 Answers1

-1

The problem here, is that the variable is declared in the global scope, so regardless of using let it becomes global.

You can use let insisde a block, and that binding then will be visible only inside the block.

See this for further info: https://www.w3schools.com/js/js_let.asp

g_bor
  • 1,077
  • 6
  • 14