0
var name = ["a","b","c"]
alert(name[1])
//alert will return ,

if i change name to array or var to let, the code will return b normally. Why does this happen?

  • 1
    it is a reserved property of `window`. please see above link. – Nina Scholz Oct 06 '20 at 20:46
  • Thank you for your answer. I still don't understand why ```let``` allows me to name my variable ```name``` without any problem – th3virtuos0 Oct 08 '20 at 04:17
  • `let` creates a local scope. the variables from the outer scope with the same name are not available. in this case you get a new variable and this allows to chage the content of it. – Nina Scholz Oct 08 '20 at 07:00

0 Answers0