Skip to content

Instantly share code, notes, and snippets.

@nola
Created November 26, 2013 01:33
Show Gist options
  • Select an option

  • Save nola/7652041 to your computer and use it in GitHub Desktop.

Select an option

Save nola/7652041 to your computer and use it in GitHub Desktop.
Null, Undefined, Empty Checks Shorthand When creating new variables sometimes you want to check if the variable your referencing for it’s value isn’t null or undefined. I would say this is a very common check for JavaScript coders.
if (variable1 !== null || variable1 !== undefined || variable1 !== '') {
var variable2 = variable1;
}
//short hand
var variable2 = variable1 || '';
@shengoo
Copy link
Copy Markdown

shengoo commented Apr 24, 2014

you should declare variable1 first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment