Created
November 21, 2010 15:45
-
-
Save founddrama/708826 to your computer and use it in GitHub Desktop.
Type coercion and other of JavaScript's dirty tricks.
This file contains hidden or 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
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@see
http://blog.founddrama.net/2010/08/some-of-javascripts-dirty-tricks/