types
# Node.js
// primitives
const myBool = true;
const myNumber = 10;
const myString = "foo";
const mySymbol = Symbol("bar");
const myNull = null;
const myUndefined = undefined;
// object types
const myObject = {};
const myArray = [];
const myFunction = function () {};
const myError = new Error("error");
const myDate = new Date();
const myRegex = /a/;
const myMap = new Map();
const mySet = new Set();
const myPromise = Promise.resolve();
const myGenerator = function* () {};
const myClass = class {};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Go
package main
func main() {
// primitives
var myBool bool = true
var myInt int = 10
var myInt8 int8 = 10
var myInt16 int16 = 10
var myInt32 int32 = 10
var myInt64 int64 = 10
var myUint uint = 10
var myUint8 uint8 = 10
var myUint16 uint16 = 10
var myUint32 uint32 = 10
var myUint64 uint64 = 10
var myUintptr uintptr = 10
var myFloat32 float32 = 10.5
var myFloat64 float64 = 10.5
var myComplex64 complex64 = -1 + 10i
var myComplex128 complex128 = -1 + 10i
var myString string = "foo"
var myByte byte = 10 // alias to uint8
var myRune rune = 'a' // alias to int32
// composite types
var myStruct struct{} = struct{}{}
var myArray []string = []string{}
var myMap map[string]int = map[string]int{}
var myFunction func() = func() {}
var myChannel chan bool = make(chan bool)
var myInterface interface{} = nil
var myPointer *int = new(int)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
编辑 (opens new window)
上次更新: 2022/09/30, 11:34:22