Menu

gitpiper

JavaScript lazy shortcuts Cheat Sheet in April 2024

Last Updated: 5 April 2024

README.md

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.


338+ more cheat sheets for you in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️