Learning golang as a javascript developer

After a decade of working with JavaScript, primarily TypeScript, I’ve recently become interested in exploring new languages. In the past few months, Go (Golang) has particularly caught my attention. Today, I’ll be comparing these two languages from my perspective.

Facts

  1. Performance: Go outperforms JavaScript in both memory usage and overall performance. However, with the introduction of the Bun.js runtime, JavaScript performance has become more comparable ( see [3], [4] ). Despite this, Go remains the stronger choice for performance-critical applications.

  2. Both languages treat functions as first-class entities, allowing them to be passed as arguments, returned as values, nested within other functions, and to form closures.

  3. Release year:

    • Go was publicly announced in November 2009, and version 1.0 was released in March 2012
    • JavaScript was invented by Brendan Eich in 1995. It was developed for Netscape 2, and became the ECMA-262 standard in 1997. The language saw a major evolution in 2015 with the release of ES6 (also known as ECMAScript 2015), which introduced significant features like ES modules, making JavaScript more powerful and versatile.
  4. Number of keywords ( for, if, etc.)

    • Go has 25 keywords
    • JavaScript has 63 keywords

High level

FeatureGoJavaScript
Type SystemStatically typedDynamically typed
CompilationCompiles to machine codeInterpreted by browsers or by runtime like Node.js, Bun.js etc.
ConcurrencyMulti-threaded via goroutinesEvent-driven, non-blocking, single-threaded via the event loop
SpeedGenerally faster due to compiled nature and lower-level accessSlower compared to Go, especially in CPU-intensive tasks
Memory ManagementGarbage collection (GC)Garbage collection (GC)
EcosystemFocused on backend services, cloud-native apps, and microservicesMassive ecosystem for frontend and backend (Node.js), supports web and mobile applications
Error HandlingExplicit error handling via error return typeException handling with try/catch like in other languages
ToolingBuilt-in tools (e.g., go fmt, go build, go test)Tooling support via multiple third-party, like npm, tsc, eslint, prettier, webpack etc.
Compilation SpeedVery fast compilation, designed for speedRelatively fast but depends on the tooling
GenericsSupported (since Go 1.18)Supported
Inheritance/CompositionNo classical inheritance; uses compositionSupports classical inheritance (via class and extends)
Null/Undefined SafetyNo concept of null, only nil for pointers and referencesHas null, undefined, and optional chaining for safety
Use CaseBackend services, microservices, high-performance apps, cloud-native systemsWeb development, full-stack applications, mobile apps (via frameworks like React Native), server-side (Node.js)
DeploymentProduces a single binary executableRequires Node.js runtime or browsers for execution
Learning CurveEasier for those with experienceEasier for beginners, especially for web developers

Syntax

Variables

Functions

Loops

Conditionals

Structs vs Classes

Interfaces

Error Handling

Concurrency

References