How to check if a variable exists or defined in JavaScript
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Use the
typeof
operatorIf you want to check whether a variable has been initialized or defined (i.e. test whether a variable has been declared and assigned a value) you can use the
typeof
operator.The most important reason of using the
need an explanation for this answer? contact us directly to get an explanation for this answertypeof
operator is that it does not throw the ReferenceError if the variable has not been declared. Let's take a look at the following example: