Back to Cheatsheets

JavaScript lazy shortcuts

JavaScript

Shortcuts

{: .-left-reference}

Examples

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

Shortcuts

WhatLazy mode"The right way"
String to number+strparseInt(str, 10) or parseFloat()
Math floor`num0`
Number to string'' + numnum.toString()
Date to UNIX timestamp+new Date()new Date().getTime()
Any to boolean!!valueBoolean(value)
Check array contentsif (~arr.indexOf(v))if (arr.includes(v))
{: .-left-align.-headers}

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