Sitemap
Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Member-only story

Inline: a series about owning your business logic

JavaScript Type Names

Living with the type system we love to hate.

5 min readOct 1, 2024

--

Press enter or click to view image in full size
Photo by Philippe Yuan on Unsplash

This is part of the Inline series, a series of copy-paste code solutions to reduce our dependency on third-party packages. Please do review the About page before reading or commenting.

Skill level: beginner

If you do not have a Medium subscription, please do read the free version here.

The problem space

We are going to be talking about types quite a bit in this series. While I think JavaScript’s dynamic type system is one of its superpowers, I also think its implemented has some gaps. One such gap is in type names.

The primary language feature for type names in JavaScript is the typeof expression. Unfortunately, it does not provide a consistent experience. That’s HR speak for “it kind of sucks”. Here’s what it gives us:

typeof undefined         // 'undefined'
typeof null // 'object'
typeof 'foo' // 'string'
typeof new String('foo') // 'object'
typeof {} // 'object'
typeof [] // 'object'
typeof 42 // 'number'
typeof true // 'boolean
typeof /foo/g // 'object'…

--

--

Charles Sullivan
Charles Sullivan

Written by Charles Sullivan

Software developer, opera singer, cook, scientist, humanist...I spend half my time seeking evidence and the other half delighting in the mess that is humanity.