1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-10-15 15:08:27 +02:00
cheatsheets/js-lazy.md
Rico Sta. Cruz 511de900ba
Formatting updates (#2133)
- Update some sheets which have very long sections
- Remove `layout: 2017/sheet` (everything has the same layout now)
- Remove outdated sheets
2024-04-03 18:30:24 +11:00

795 B

title, category
title category
JavaScript lazy shortcuts JavaScript

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.