Is JavaScript an untyped language?

JavaScript is untyped:


(source: no.gd)

Even Brendan Eich says so. On Twitter, he replied to a thread that linked to this question:

… academic types use “untyped” to mean “no static types”…

So the problem is that there’s a few different definitions of untyped.

One definition has been talked about in one of the above answers – the runtime doesn’t tag values and just treats each value as bits. JavaScript does tag values and has different behaviour based on those tags. So JavaScript obviously doesn’t fit this category.

The other definition is from Programming Language Theory (the academic thing that Brendan is referring to). In this domain, untyped just means everything belongs to a single type.

Why? Because a language will only generate a program when it can prove that the types align (a.k.a. the Curry-Howard correspondence; types are theorems, programs are proofs). This means in an untyped language:

  1. A program is always generated
  2. Therefore types always match up
  3. Therefore there must only be one type

In contrast to a typed language:

  1. A program might not be generated
  2. Because types might not match up
  3. Because a program can contain multiple types

So there you go, in PLT, untyped just means dynamically typed and typed just means statically typed. JavaScript is definitely untyped in this category.

See also:

Leave a Comment