0

Since i have not declared the variable anywhere , why am i getting a value for it rather than an error . I am directly assigning it a value and not declaring it first.

let x = [0 ,1]

if(x){
    target = x[0]
}
console.log(target)

I was expecting an reference error but got value for target that was 0

White Wizard
  • 608
  • 3
  • 19
  • Because that's how JavaScript was designed. Use [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) to get an error. – Teemu Dec 27 '22 at 06:23

0 Answers0