Skip to content

Instantly share code, notes, and snippets.

@siberex
Last active August 3, 2025 15:50
Show Gist options
  • Save siberex/62d0a6a71f3b3e9471be9cf47c2c4556 to your computer and use it in GitHub Desktop.
Save siberex/62d0a6a71f3b3e9471be9cf47c2c4556 to your computer and use it in GitHub Desktop.
Golang vs Node.js slices
package main
import "fmt"
func main() {
a1 := []int{1, 2, 3, 4, 5}
a2 := a1[1:3]
a2 = append(a2, 10, 20)
fmt.Println(a1) // [1 2 3 10 20]
fmt.Println(a2) // [2 3 10 20]
// Slice is a reference until it is not, lol
// append beyond capacity will make a copy:
// a2 = append(a2, 10, 20, 30)
}
let a1 = [1, 2, 3, 4, 5];
let a2 = a1.slice(1, 3);
a2.push(10, 20);
console.log(a1); // [ 1, 2, 3, 4, 5 ]
console.log(a2); // [ 2, 3, 10, 20 ]
@siberex
Copy link
Author

siberex commented Aug 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment