3

var status = false;
status === false ? alert('Example1') : alert('Example2');

Can anyone please tell me why it not working as my expectation. Why it not returning Example1?

Rushabh Shah
  • 133
  • 1
  • 4
  • 4
    Because `window.status` already exists, and can only be a string (global properties can get [implicitly referred to](https://stackoverflow.com/questions/54776759/how-to-run-code-without-implicitly-referring-to-properties-on-the-global-object) unfortunately) – CertainPerformance Feb 20 '19 at 04:34
  • [boolean in an if statement](https://stackoverflow.com/q/15393935/4229270) – Sinto Feb 20 '19 at 04:36
  • 1
    @Sinto The problem here is the fact that the variable is named "status", is declared with "var", and on the top level - the other question, while useful, isn't exactly applicable – CertainPerformance Feb 20 '19 at 04:37
  • He can use it if required. @CertainPerformance: anyway thanks for the response. – Sinto Feb 20 '19 at 04:38
  • But why doesn't throw this error (`SyntaxError: missing variable name`) like var delete = 1; – デビット Feb 20 '19 at 04:39
  • @デビット Because `status` is not a [reserved word](https://tc39.github.io/ecma262/#sec-reserved-words). – Amadan Feb 20 '19 at 04:47

0 Answers0