Javascript Exceptions - testing for true - When is undefined actually undefined?

Javascript has to know what 'it' is before Javascript can tell if 'it' is what you want 'it' to be. Example:
if (unreferencedVariableName) { alert('Impossible! an unreferenced variable cannot return true. In fact it cannot return at all!'); }
Result: ReferenceError: unreferencedVariableName is not defined
/* is as true as the unescapable pain and suffering of being an alive human being  */
if (typeof(cowBoySuckMonkey) === 'undefined') { console.log('suck it!') }


/*   these are false - no if-fu for you!   */
if (typeof(cowBoySuckMonkeee) != 'undefined') { console.log('suck it again!') }
if (!typeof(cowBoySuckMonkeee)) { console.log('suck it for real!') }

/* 'undefined is something I guess - just not what I wanted to test against */
if (typeof(cowBoySuckMonke)) { console.log('suck it nut gobbler!') }

var cowboySuckMonkay = '';
if (typeof(cowboySuckMonkay) != 'undefined') { console.log('suck it empty string!') }
/* no joy */
if (typeof(cowboySuckMonkay)) { console.log('suck it empty string, part duex!') }

/* well, I guess an empty string is false - CaulkGobblin! */
if (cowboySuckMonkay) { console.log('suck it empty string, you still not true!') }

if (cowboySuckMonkay == '') { console.log('suck it empty string, now you true!') }
so much to remember…

Posted by jeremy Tue, 18 Aug 2009 22:06:00 GMT


comparison of Fixnum with String failed

Where the error occured

Rails 2.1.2 / bundle_fu / Javascript file

Why the fu…?

A javascript files that ends with a line commented out. -1 is being compared to an empty string.

Fix

Add a blank line at the end of the Javscript file(s) that end with commented lines.

Posted by jeremy Sat, 15 Aug 2009 14:45:00 GMT


snipdbits

I've been rocking the Javascript one liners lately. Syntax like this is way not noob friendly.
// both are the same
  if ( 0 == 0 && 0 === 0)
    alert('0 is equal to 0, and 0 is the same value and object type as 0');


  if ( 0 == 0 && 0 === 0)  alert('0 is equal to 0, and 0 is the same value and object type as 0');

Posted by jeremy Thu, 06 Aug 2009 15:28:00 GMT