Let's have some fun with type casting in javascript today :
Do you know what is:
what about:
but wait, what is this:
boolean:
meet miss tilde:
a real fun:
You just saw hidden treasure of our favourite language.
Happy Coding :)
Do you know what is:
"2" // string as we know
what about:
+"2" // number
but wait, what is this:
1 + +"2" // 3 1 - - "3" // 4
boolean:
+true // 1 +false // 0 -true // -1 -false // 0 !!true // true !!false // false
meet miss tilde:
~true // -2 ~~true // 1 ~false // -1 ~~false // 0 1 - ~true // 3 1 + ~~false // 1
a real fun:
- ~ -2 // -1 - ~false //1 - ~0 // 1 ! ~ -2 // false ! ~ -1 //true
You just saw hidden treasure of our favourite language.
Happy Coding :)
No comments:
Post a Comment