Last active
December 21, 2015 01:59
-
-
Save alcedo/6232023 to your computer and use it in GitHub Desktop.
JavaScript Quirks and notes
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
/*********** Checking for not defined / undefined **********/ | |
foo | |
// ReferenceError: foo is not defined | |
if(foo == null) console.log('this wont work'); | |
// ReferenceError: foo is not defined | |
if (typeof foo == 'undefined' ) console.log('foo is undef'); | |
// this is the only way to check for not defined | |
var foo; //define foo, but foo has no value | |
if (typeof foo == 'undefined' ) console.log('foo is undef'); | |
//this works | |
if ( foo == undefined ) console.log('foo is undef'); | |
// this works | |
null // used to indicate a deliberate non-value | |
undefined // used to indicate a value that hasn't been set yet | |
///////////////// | |
var test = someObject.methodTest; | |
test(); | |
//Due to the first case, test now acts like a plain function call; therefore, this inside it will no longer refer to someObject. ie: LHS of test is window object | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment