1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-06-16 07:07:37 +02:00
cheatsheets/js-lazy.md
Rico Sta. Cruz 8ae383e42a
Update
2017-08-29 01:39:39 +08:00

814 B

title category layout
JavaScript lazy shortcuts JavaScript 2017/sheet

Shortcuts

{: .-left-reference}

Examples

n = +'4096'    // n === 4096
s = '' + 200   // s === '200'
now = +new Date()
isPublished = !!post.publishedAt

Shortcuts

What Lazy mode "The right way"
String to number +str parseInt(str, 10) or parseFloat()
Math floor `num 0`
Number to string '' + num num.toString()
Date to UNIX timestamp +new Date() new Date().getTime()
Any to boolean !!value Boolean(value)
Check array contents if (~arr.indexOf(v)) if (arr.includes(v))
{: .-left-align.-headers}

.includes is ES6-only, otherwise use .indexOf(val) !== -1 if you don't polyfill.