2 title: JavaScript lazy shortcuts
13 n = +'4096' // n === 4096
14 s = '' + 200 // s === '200'
19 isPublished = !!post.publishedAt
24 | What | Lazy mode | "The right way" |
26 | String to number | `+str` | `parseInt(str, 10)` _or_ `parseFloat()` |
27 | Math floor | `num | 0` | `Math.floor(num)` |
28 | Number to string | `'' + num` | `num.toString()` |
29 | Date to UNIX timestamp | `+new Date()` | `new Date().getTime()` |
30 | Any to boolean | `!!value` | `Boolean(value)` |
31 | Check array contents | `if (~arr.indexOf(v))` | `if (arr.includes(v))` |
32 {: .-left-align.-headers}
34 `.includes` is ES6-only, otherwise use `.indexOf(val) !== -1` if you don't polyfill.