jsrosetta

Cơ bản

In ra output

console.log/console.error trong Node.js so với fmt.Println/Printf (Go), println!/eprint! (Rust), print (Swift) và IO.println (Java 25).

Phiên bản tối thiểu
Node.js ≥ 12.20Go ≥ 1.0Rust ≥ 1.19Swift ≥ 3.0Java ≥ 25
Đã chạy thử trên
Node.js 24.12.0Go 1.27.1Rust 1.98.1Swift 6.2.4Java 25.0.4.1

Code Node.js là ES module: lưu file .mjs hoặc đặt "type": "module" trong package.json.

console.log in ra stdout, console.error in ra stderr. Go tách các hàm rõ ràng hơn: fmt.Println in kèm xuống dòng, fmt.Printf nhận format string kiểu C, còn fmt.Fprintf ghi vào bất kỳ io.Writer nào — kể cả os.Stderr. Rust có macro tương đương (println!/eprint!) ngay trong ngôn ngữ; Swift chỉ có print đơn giản nên cần Foundation cho định dạng kiểu C và ghi ra stderr; Java 25 thêm IO.println cho compact source file, còn System.err vẫn dùng như trước.

In ra stdout và stderr

console.log('print to stdout')
console.log('format %s %d', 'example', 1)
console.error('print to stderr')
print to stdout
format example 1
print to stderr

Tham khảo: github.com/miguelmota/golang-for-nodejs-developers#printing