How do I stop getting this ReferenceError in node.js?-Collection of common programming errors

    183|             });
    184| 
 >> 185|             
    186|                 alert("Welcome!");
    187|             
    188| 

just_registered is not defined

Basically, I want to say: if just_registered is defined and is true, then alert. However, I want want to set everything to false…I just want to leave it undefined (i have like 100 variables)

  1. Basically your checking whether a local variable exists. To do this you have to use the typeof operator since accessing just_registered which is an undeclared local variable creates a reference error.

    This is best compared to

    var foo;
    if (foo) { }
    

    vs

    //var foo;
    if (foo) { } // ReferenceError
    

    Where as

    //var foo
    if (typeof foo !== "undefined") { } 
    

    Will work because accessing an undeclared variable with the typeof operator just returns "undefined" rather then throwing a ReferenceError

Originally posted 2013-11-09 20:50:49.