variables
# Node.js
// function scoped
var foo = "foo";
// block scoped
let bar = "bar";
// constant
const qux = "qux";
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Go
(variables are block scoped in Go)
package main
func main() {
// explicit
var foo string = "foo"
// type inferred
var bar = "foo"
// shorthand
baz := "bar"
// constant
const qux = "qux"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
编辑 (opens new window)
上次更新: 2022/09/30, 11:34:22