0
var name={id:"12"}
console.log(name) // logs [object Object] 

But the following variations log the object correctly

//Variation 1-changing "name" to "name1"
var name1={id:"12"}
console.log(name1) // logs {id:"12"}

//Variation 2-changing "var" to "let"
let name={id:"12"}
console.log(name) // logs {id:"12"}

Why does this happen? Edit:-This is different from any other questioner-let question on stack overflow!

Purnima Naik
  • 419
  • 1
  • 5
  • 16
  • 2
    No, it's really not different from the other question. A global `var name` does nothing because `window.name` is already defined, and `window.name` is type-locked to a string. – Niet the Dark Absol Oct 23 '20 at 02:04
  • 1
    [This answer](https://stackoverflow.com/a/4862268/12407908) (to a different question) describes your variation #2. You're basically asking about the difference between `var` and `let` in the global scope. The answer I linked is *very* comprehensive. –  Oct 23 '20 at 02:05

0 Answers0