Why do some variables declared using let inside a function become available in another function, while others result in a reference error?

前端 未结 8 1124
说谎
说谎 2021-01-30 03:45

I can\'t understand why variables act so strange when declared inside a function.

  1. In the first function I declare with let the variabl

8条回答
  •  余生分开走
    2021-01-30 04:01

    It's because of when you don't use let or var then variable is getting declare on the fly, better you declare like following.

    let a = 10;
    let b = 10;
    let c = 10;
    

提交回复
热议问题