types


Node.js

  1. // primitives
  2. const myBool = true
  3. const myNumber = 10
  4. const myString = 'foo'
  5. const mySymbol = Symbol('bar')
  6. const myNull = null
  7. const myUndefined = undefined
  8. // object types
  9. const myObject = {}
  10. const myArray = []
  11. const myFunction = function() {}
  12. const myError = new Error('error')
  13. const myDate = new Date()
  14. const myRegex = /a/
  15. const myMap = new Map()
  16. const mySet = new Set()
  17. const myPromise = Promise.resolve()
  18. const myGenerator = function *() {}
  19. const myClass = class {}

Go

  1. package main
  2. func main() {
  3. // primitives
  4. var myBool bool = true
  5. var myInt int = 10
  6. var myInt8 int8 = 10
  7. var myInt16 int16 = 10
  8. var myInt32 int32 = 10
  9. var myInt64 int64 = 10
  10. var myUint uint = 10
  11. var myUint8 uint8 = 10
  12. var myUint16 uint16 = 10
  13. var myUint32 uint32 = 10
  14. var myUint64 uint64 = 10
  15. var myUintptr uintptr = 10
  16. var myFloat32 float32 = 10.5
  17. var myFloat64 float64 = 10.5
  18. var myComplex64 complex64 = -1 + 10i
  19. var myComplex128 complex128 = -1 + 10i
  20. var myString string = "foo"
  21. var myByte byte = 10 // alias to uint8
  22. var myRune rune = 'a' // alias to int32
  23. // composite types
  24. var myStruct struct{} = struct{}{}
  25. var myArray []string = []string{}
  26. var myMap map[string]int = map[string]int{}
  27. var myFunction func() = func() {}
  28. var myChannel chan bool = make(chan bool)
  29. var myInterface interface{} = nil
  30. var myPointer *int = new(int)
  31. }