Javascript is insane
Mar. 15th, 2013 06:58 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
'' == '0' // false 0 == '' // true 0 == '0' // true !0 == true // true !1 == false // true false == 'false' // false false == '0' // true false == undefined // false false == null // false null == undefined // true " \t\r\n" == 0 // true NaN === NaN // false !!NaN === !!NaN // trueI recently saw someone prefacing their code with
var t=!0;... Because they wanted to save space in their code by replacing every occurrence of true with t, and also wanted so save two bytes while declaring what t was.
And I thought Perl invited abuse!
If you see anyone doing this, pour your drink on their head.
no subject
Date: 2013-03-16 03:52 am (UTC)Seems it would make JS compression a tool only for code obfuscators...
Speaking of which, I'm learning all about the fun to be had by replacing "if" statements with the "&&" operator, and using the Javascript comma to chain together statements for no good reason, by reading obfuscated code: