Skip to content

Instantly share code, notes, and snippets.

@rafbm
Created June 30, 2010 13:36
Show Gist options
  • Save rafbm/458655 to your computer and use it in GitHub Desktop.
Save rafbm/458655 to your computer and use it in GitHub Desktop.
/**
* ♫ A Little Reminder About JavaScript Boolean Evaluations ♫
*/
!!0 // false
!!NaN // false
!![] // true
!!new Array // true
!!{} // true
!!new Object // true
!!'' // false
!!new String // true, mmh mmh... †
!!null // false
!!undefined // false
!!new Date // true
// †
/**
* ♫ A Little Study About How JavaScript Strings Are (a little bit) Fucked ♫
*/
'' === new String // false
'' == new String // true
// Because...
'' // ""
new String // "[object Object]"
typeof '' // "string"
typeof new String // "object"
// ...and...
(new String).toString() // ""
''.toString() // ""
// So a string can be either an Object or a String,
// but I have yet to find what difference it makes,
// since in both cases it has all the string methods and properties...
(new String).length // 0
('').length // 0
(new String).indexOf('foo') // -1
('').indexOf('foo') // -1
(new String).__proto__ // the whole thing
('').__proto__ // that same whole thing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment