Basics
Comments
Line (`//`) and block (`/* */`) comments use the exact same syntax across all five languages — the only difference is doc-comment convention.
- Minimum versions
- Node.js ≥ 12.20Go ≥ 1.0Rust ≥ 1.58Swift ≥ 5.1Java ≥ 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, Go, Rust, Swift, and Java all share the exact same comment syntax: // for a single line, /* ... */ for a multi-line block (Rust and Swift both allow nesting block comments, unlike JS/Go/Java). There's nothing new to learn here — the real difference only shows up once a comment sits right above a declaration and becomes a doc comment: JSDoc in Node.js, godoc in Go, rustdoc in Rust, doc comments in Swift, Javadoc in Java.
Line and block comments
// this is a line comment
/*
this is a block comment
*/package main
func main() {
// this is a line comment
/*
this is a block comment
*/
}fn main() {
// this is a line comment
/*
this is a block comment
*/
}// this is a line comment
/*
this is a block comment
*/void main() {
// this is a line comment
/*
this is a block comment
*/
}Doc comments: JSDoc, godoc, rustdoc, Swift, Javadoc
/**
* Returns a greeting for the given name.
* @param {string} name
* @returns {string}
*/
function greet(name) {
return `Hello, ${name}!`
}
console.log(greet('Go')) // Hello, Go!package main
import "fmt"
// Greet returns a greeting for the given name.
func Greet(name string) string {
return "Hello, " + name + "!"
}
func main() {
fmt.Println(Greet("Go")) // Hello, Go!
}/// Returns a greeting for the given name.
fn greet(name: &str) -> String {
format!("Hello, {name}!")
}
fn main() {
println!("{}", greet("Go")); // Hello, Go!
}/// Returns a greeting for the given name.
/// - Parameter name: the name to greet.
/// - Returns: the greeting string.
func greet(_ name: String) -> String {
"Hello, \(name)!"
}
print(greet("Go")) // Hello, Go!/**
* Returns a greeting for the given name.
*
* @param name the name to greet
* @return the greeting string
*/
String greet(String name) {
return "Hello, " + name + "!";
}
void main() {
IO.println(greet("Go")); // Hello, Go!
}A Go doc comment must start with the exact name of the identifier it describes (Greet returns...) for go doc/godoc and editors to recognize it; JSDoc uses a /** ... */ block with @param/@returns tags so tools like VS Code and TypeScript can infer types and show hints. rustdoc (///) doesn't need to start with the function's name the way Go does, and it renders real Markdown (including runnable doctests). Swift uses /// with - Parameter/- Returns markers so Xcode/DocC can show Quick Help. Javadoc uses /** ... */ with @param/@return tags, even for top-level methods in a Java 25 compact source file.
Reference: github.com/miguelmota/golang-for-nodejs-developers#comments