Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xxl007/11122955 to your computer and use it in GitHub Desktop.
Save xxl007/11122955 to your computer and use it in GitHub Desktop.
Checking for an Existing, Nonempty String
//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