Introduction: Transpiled to Compiled Binary
Introduction
Introduction
In this lesson, you'll learn about introduction: transpiled to compiled binary in Go. Coming from TypeScript, you already have a foundation for understanding this concept. We'll build on that knowledge while highlighting the key differences.
In TypeScript, you're familiar with introduction.
Go has its own approach to introduction, which we'll explore step by step.
The Go Way
Let's see how Go handles this concept. Here's a typical example:
// Go — compiles to a single native binary
package main
import "fmt"
func main() {
greeting := "Hello, World!"
fmt.Println(greeting)
fmt.Println(add(2, 3))
}
func add(a int, b int) int {
return a + b
}Comparing to TypeScript
Here's how you might have written similar code in TypeScript:
// TypeScript — transpiles to JS, runs on Node.js
const greeting: string = "Hello, World!";
console.log(greeting);
function add(a: number, b: number): number {
return a + b;
}
console.log(add(2, 3));You may be used to different syntax or behavior.
Go compiles to a single self-contained native binary — no runtime required
You may be used to different syntax or behavior.
Every Go file belongs to a package; the entry point is package main with func main()
You may be used to different syntax or behavior.
:= is short variable declaration (type inferred)
You may be used to different syntax or behavior.
fmt.Println replaces console.log
Step-by-Step Breakdown
1. Single Native Binary
Go compiles directly to a native executable with no external runtime or interpreter. Deployment is a single binary — no node_modules, no JVM.
tsc index.ts && node index.jsgo build -o myapp main.go
./myapp # single binary, no runtime needed2. package main and func main()
Every Go source file declares a package. The executable entry point is func main() in package main. Libraries use other package names.
// TypeScript: top-level code runs directlypackage main
func main() {
// entry point
}3. := Short Variable Declaration
:= declares and assigns a variable with inferred type. It can only be used inside functions. var is used at package level.
const name = "Alice"; // inferred as string
let count = 0;name := "Alice" // inferred as string
count := 0 // inferred as int
// Or explicit:
var name string = "Alice"4. fmt Package
Go's fmt package handles printing and formatting. fmt.Println adds a newline. fmt.Printf uses format verbs like %s, %d, %v.
console.log(`Hello, ${name}! You are ${age} years old.`);fmt.Printf("Hello, %s! You are %d years old.\n", name, age)
// or with fmt.Sprintf for string formatting:
msg := fmt.Sprintf("Hello, %s!", name)Common Mistakes
When coming from TypeScript, developers often make these mistakes:
- Go compiles to a single self-contained native binary — no runtime required
- Every Go file belongs to a package; the entry point is package main with func main()
- := is short variable declaration (type inferred)
Key Takeaways
- Go compiles to a single native binary — no runtime or interpreter needed
- Entry point is func main() in package main
- := declares and infers type in one step
- fmt.Println/Printf replaces console.log