0
const fun = () => console.log(variable);

let variable;

variable = 'some string';

fun();

Hello, guys I,m interested how JS works in this situation. In the function declaration I'm logging variable that is not declared yet. Output is 'some string'. So I'm interested is it because undeclared, but assigned variables become global variables?

evolutionxbox
  • 3,703
  • 5
  • 35
  • 49
Vagabond
  • 1
  • 1
  • I think it's because you give `variable` a value before `fun` is called. Try putting `fun()` before the variable definition. You should see an error. Also, there are no globals here. – evolutionxbox May 12 '22 at 19:08

0 Answers0