jsrosetta

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
*/

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!

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