Skip to content

Latest commit

 

History

History
27 lines (24 loc) · 774 Bytes

random_javascript_quizzes.md

File metadata and controls

27 lines (24 loc) · 774 Bytes

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.