JS One Liners

Published: Jan. 3, 2022, 11 a.m.

In this Hasty Treat, Scott and Wes talk about some Javascript one liners that speed up your coding experience in one line.

Sponsor - Linode

Whether you\u2019re working on a personal project or managing enterprise infrastructure, you deserve simple, affordable, and accessible cloud computing solutions that allow you to take your project to the next level. Simplify your cloud infrastructure with Linode\u2019s Linux virtual machines and develop, deploy, and scale your modern applications faster and easier. Get started on Linode today with a $100 in free credit for listeners of Syntax. You can find all the details at\xa0linode.com/syntax. Linode has 11 global data centers and provides 24/7/365 human support with no tiers or hand-offs regardless of your plan size. In addition to shared and dedicated compute instances, you can use your $100 in credit on S3-compatible object storage, Managed Kubernetes, and more. Visit\xa0linode.com/syntax\xa0and click on the \u201cCreate Free Account\u201d button to get started.

Sponsor - Sentry

If you want to know what\u2019s happening with your code, track errors and monitor performance with Sentry. Sentry\u2019s Application Monitoring platform helps developers see performance issues, fix errors faster, and optimize their code health. Cut your time on error resolution from hours to minutes. It works with any language and integrates with dozens of other services. Syntax listeners new to Sentry can get two months for free by visiting\xa0Sentry.io\xa0and using the coupon code TASTYTREAT during sign up.

Show Notes
  • 00:24:12\xa0Welcome
  • 01:24:11\xa0Sponsor: Linode
  • 02:11:02\xa0Sponsor: Sentry
  • 03:54:18\xa0Twitter ask for One Liners
  • 04:24:05\xa0Math random\xa0const getPsuedoID =() => Math.floor(Math.random() * 1e15);
  • 05:43:09\xa0Random color
  • Paul Irish random color\xa0'#'+Math.floor(Math.random()*16777215).toString(16);
  • 06:41:06\xa0Console.log as an object.\xa0console.log({ dog, person });\xa0VS Marketplace Link
  • 08:29:17\xa0Edit anything\xa0document.designMode = "on"
  • 10:15:15\xa0Temporal date\xa0export const today = Temporal.Now.plainDateISO();
  • 11:44:05\xa0Console(log)\xa0const myFunc = (age) \u21d2 console.log(age) || updateAge()
  • 13:26:13\xa0Remove a prop\xa0const { propToRemove, ...rest } = obj;
  • 15:29:01\xa0PHP style debugging\xa0preElement.innerText ={JSON.stringify(val, '', ' ')}`
  • 16:31:00\xa0First and Last Destructure\xa0var {0: first, length, [length - 1]: last} = [1,2,3];
  • 17:34:17\xa0Speed up audio video\xa0document.querySelector('audio, video\u2019).playbackRate = 2
  • Overcast
  • 19:44:15\xa0Sleep function\xa0let sleep = (time = 0) => new Promise(r => setTimeout(r, time))
  • 20:26:00\xa0If statements on one line\xa0If (!thing) return 'something'
Tweet us your tasty treats