Why is my variable "status" showing up deprecated in my code?

Viewed 422

Why is my variable status showing up deprecated in my code? How do you fix this? Sorry, I'm fairly knew to JavaScript.

var age = prompt("what is your age?");

if (age >= 18 && age <= 35) {
  status = "target demo";
  console.log(status);
} else {
  status = "not my audience";
  console.log(status);
}

1 Answers

The problem arises because you are trying to use the status variable without defining it, as @epascarello pointed out; If you use the status variable without defining it, you are overwriting the Window.status[1] property, but you do not get the warning that the status variable is not defined.

As @maksymiuk stated, if you use the status variable by defining it yourself, you will write it to the status variable that you do not recognize, not the Window.status property.

var age = prompt("what is your age?");
let status;

if (age >= 18 && age <= 35) {
  status= "target demo";
  console.log(status);
} else {
  status= "not my audience";
  console.log(status);
}


1 - Window.status

Related