Skip to main content

22 posts tagged with "javascript"

Posts about JavaScript

View All Tags

Mouse, Touch and Pointer events

· 6 min read
Filip Tammergård
Software Engineer at Frilans Finans

I recently stumbled upon a bug related to the subtle differences between mouse, touch and pointer events. The bug made me confused—and curious. What is actually the difference between these events?

I opened an issue for the bug that you can check out if you're also curious—but before trying to understand the bug, we need to set the stage with some knowledge around different types of events.

|| vs ??

· 2 min read
Filip Tammergård
Software Engineer at Frilans Finans

|| and ?? are similar, but there's some very important nuance. Take a look at this example:

const a = "" || "default value"
// > "default value"

const b = "" ?? "default value"
// > ""

Let me explain.

IP Location

· One min read
Filip Tammergård
Software Engineer at Frilans Finans

You live close to , right?

How did I know that? I used Ipapi! A neat API for getting the location of IP addresses, with 30,000 free lookups per month.

Utility function: getRandomColor

· One min read
Filip Tammergård
Software Engineer at Frilans Finans

I've had some fun with random colors lately! To speed up development, I made a utility function for getting a random color. It's really simple:

export const getRandomColor = () => {
const red = Math.floor(Math.random() * 256)
const green = Math.floor(Math.random() * 256)
const blue = Math.floor(Math.random() * 256)

const color = `rgb(${red}, ${green}, ${blue})`

return color
}

Slugify string

· One min read
Filip Tammergård
Software Engineer at Frilans Finans

When you generate URLs from titles, the title typically can't be used directly — spaces, question marks and other special characters don't belong in URL slugs. That's where a slugify function comes in handy.