Created
April 20, 2014 19:31
-
-
Save xxl007/11122955 to your computer and use it in GitHub Desktop.
Checking for an Existing, Nonempty String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Use a combination of the typeof operator, the valueof method (shared by all objects) and the length property of String objects | |
// true if variable exists, is a string, and has a length greater than zero | |
if (( | |
(typeof unkownVariable != "undefined") | |
&& (typeof unknownVariable.valueOf() == "string") | |
&& (unknownVariable.length > 0) | |
)) { | |
} | |
// typeof may return: "number", "string", "boolean", "function", "object", or "undefined" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment