jsrosetta

Types

Types

How JavaScript's primitive and composite types compare to Go's, Rust's, Swift's, and Java's static type systems (int8..uint64, struct, map, channel…).

Minimum versions
Node.js ≥ 12.20Go ≥ 1.18Rust ≥ 1.60Swift ≥ 1.2Java ≥ 25
Verified on
Node.js 24.12.0Go 1.27.1Rust 1.98.1Swift 6.2.4Java 25.0.4.1

Node.js code is an ES module: save it as .mjs or set "type": "module" in package.json.

JavaScript has two numeric primitive types: number (always a 64-bit double) and bigint (arbitrary-precision integers), plus a handful of built-in composite types (object, Map, Set, Promise…). Go, Rust, Swift, and Java all split numbers into several types by size and signedness, plus explicit composite types like struct/map/channel (Go and Rust), struct/class/Dictionary (Swift), or record/Map/List (Java).

Primitive and composite types

// primitives
const myBool = true
const myNumber = 10
const myString = 'foo'
const mySymbol = Symbol('bar')
const myNull = null
const myUndefined = undefined
 
// object types
const myObject = {}
const myArray = []
const myFunction = function() {}
const myError = new Error('error')
const myDate = new Date()
const myRegex = /a/
const myMap = new Map()
const mySet = new Set()
const myPromise = Promise.resolve()
const myGenerator = function *() {}
const myClass = class {}

Key differences

Node.js Go Rust Swift Java
Number types 2 types: number, bigint over a dozen: int8..uint64, complex64/128 similar to Go, plus i128/u128 (which Go lacks), except complex (external crate) Int8..UInt64, Float/Double 7 numeric primitives, char is the only unsigned one
Any type no declaration needed any (alias for interface{}, since 1.18) Box<dyn Any> (rare; generics are more idiomatic) Any Object
"Not set" value undefined a per-type zero value none — a variable must be assigned before use (definite assignment); use Option<T>::None to represent "no value" nil (only for Optional) zero value/null only applies to fields; local variables must also be assigned before use (definite assignment), just like Rust
Functions as first-class values yes yes, type func() yes, fn() or a closure yes, type () -> Void yes, via a functional interface/lambda

Reference: github.com/miguelmota/golang-for-nodejs-developers#types