Web & Dev

Programming Language Syntax

Quick side-by-side of common constructs across Python, JavaScript, Go, Rust, and more.

Variables & constants

LanguageMutable varImmutable
Pythonx = 1x: Final = 1
JavaScriptlet x = 1const x = 1
TypeScriptlet x: number = 1const x = 1 as const
Govar x int = 1 or x := 1const x = 1
Rustlet mut x = 1let x = 1
Javaint x = 1final int x = 1
C#int x = 1const int X = 1
Swiftvar x = 1let x = 1

If / else

LanguageSyntax
Pythonif x > 0:\n ...\nelse:\n ...
JavaScriptif (x > 0) { ... } else { ... }
Goif x > 0 { ... } else { ... }
Rustif x > 0 { ... } else { ... } (expression-valued)

For loop (range 0..n)

LanguageSyntax
Pythonfor i in range(n):
JavaScriptfor (let i = 0; i < n; i++)
Gofor i := 0; i < n; i++ { }
Rustfor i in 0..n { }
Swiftfor i in 0..

Define a function (add two ints)

LanguageSyntax
Pythondef add(a: int, b: int) -> int:\n return a + b
JavaScriptfunction add(a, b) { return a + b; }
TypeScriptfunction add(a: number, b: number): number { return a + b; }
Gofunc Add(a, b int) int { return a + b }
Rustfn add(a: i32, b: i32) -> i32 { a + b }
Javastatic int add(int a, int b) { return a + b; }

String formatting

LanguageSyntax
Pythonf"Hello {name}, age {age}"
JavaScript`Hello ${name}, age ${age}`
Gofmt.Sprintf("Hello %s, age %d", name, age)
Rustformat!("Hello {name}, age {age}")
JavaString.format("Hello %s, age %d", name, age)
C#$"Hello {name}, age {age}"

Null / None

PythonNone
JS / TSnull and undefined
Gonil (pointer, interface, slice, map, chan, func)
RustOption::None — no null
Java / C#null
SwiftOptional::nil
Was this article helpful?