WIP- Go for Javascript Developers
By Oguzhan Cakmak at
Go
Variable declaration is as is:
var name string
name = "Oguzhan"
const constant = 3.14When in a scope (between curly braces), you can utilize type inference
func main() {
name := "Oguzhan"
}Built in types
bool string
int int8 int16 int32 int64
uint uint8 uint16 uint32 uint64 uintptr
byte // alias for uint8
rune // alias for int32
float32 float64
complex64 complex128
```
- No semicolon at the end of the instructions
- There is no `try catch` mechanism in Go. Manuel error checking
```go
res, err = call()
if err != nil {
return
}- Functions may return multiple values
func helloWorld() -> string, error {
return "Hello World", nil
}- There is no concept of
class. Usestructinstead
type Car struct {
year int
model string
brand string
color string
}You can add methods to the struct
func (c Car) run () {
fmt.Println("Car is running")
}You can mutate existing properties of a struct
func (c *Car) changeColor(color string) {
c.color = color
}