1. Reference Type (source)
let user = {
name: "John",
go: function() { alert(this.name) }
}
(user.go)()
Answer
Uncaught ReferenceError: can't access lexical declaration 'user' before initialization
The error appears because a semicolon is missing after user={...}
, so it reads like: let user = { go:... }(user.go)()
and see we are accessing user on the line where it is not even defined yet.
After inserting ;
it will give John
as a output.