javascript布尔值_使用JavaScript布尔值剃字节

javascript布尔值

Developers are always search for ultimate way to create something with the least amount of code.  This, of course, is one of the reasons we use minifiers: to serve code as small as possible.  Of course this practice has numerous benefits, like faster download time, less storage consumption, etc.  One way that minifiers are able to shave bytes off of JavaScript code is changing the way booleans are used.

开发人员总是在寻找用最少的代码创建某些东西的最终方法。 当然,这是我们使用缩小符的原因之一:尽可能减少代码的产生。 当然,这种做法有很多好处,例如更快的下载时间,更少的存储消耗等。minifier能够从JavaScript代码中减少字节数的一种方法是更改​​布尔值的使用方式。


true === !0 // Save 2 chars

false === !1 // Save 3 chars


A few bytes of every true and false go away with the ! evaluation.  If you set one-letter variables names to those values, you may end up saving more.  Keep in mind I'm not telling you to do this in your source code -- minifiers like Uglify JS will do this for you.  Just something neat to know about though!

每个正确和错误的几个字节都会消失! 评价。 如果将一个字母的变量名称设置为这些值,则可能会节省更多。 请记住,我没有告诉您在源代码中执行此操作-像Uglify JS这样的压缩程序将为您执行此操作。 只是一些整洁的信息而已!

翻译自: https://davidwalsh.name/javascript-booleans

javascript布尔值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值