Skip to content

Instantly share code, notes, and snippets.

@founddrama
Created November 21, 2010 15:45
Show Gist options
  • Save founddrama/708826 to your computer and use it in GitHub Desktop.
Save founddrama/708826 to your computer and use it in GitHub Desktop.
Type coercion and other of JavaScript's dirty tricks.
// Date -> Number:
var d = +(new Date());
// 1281743590756
typeof d;
// number
// almost anything -> String
d += '';
// '1281743590756'
typeof d;
// string
// inspired @jdalton - https://twitter.com/#!/jdalton/status/90587625869680640
[value] == 'value';
// true
// take advantage of Array's valueOf (i.e., toString)
// anything -> Boolean
d = !!d;
// true
typeof d;
// boolean
@founddrama
Copy link
Author

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