Ask coding questions

← Back to all posts
JavaScript Undefined object?
xxpertHacker (865)

JavaScript's undefined is it's own type, it doesn't have an object wrapper class, so we can't do "object" === typeof new Undefined, but, if you run this snippet in your browser console:


which is equivalent to;

You should get the following string: [object Undefined], does this indicate that an object form of undefined could exist?

SixBeeps (5062)

According to the specs, undefined is one of the primitive data types, which is obvious, but it does mean that it is a type.
It's possible that the browser handles undefined as a special internal type to make things easier to work with, but is inaccessible to the standard programmer.

I don't have much time, but take a look through that specification and see if you find anything interesting.

xxpertHacker (865)

@SixBeeps Well, I'm pretty sure that %Object%.prototype.toString% uses Type, so it's declaration would probably be somewhere along the lines of:

function toString() {
    const type = Type(this);
    return `[object ${type}]`;

I can probably find the spec algorithm.

Either way, it would be interesting if an object form exists, and even more so if it were exposed.