These are some basic GO questions that I've gathered from the interviews.
I will be posting the questions Post As You Go, where I will gather a post from different interviews that I attend.
- What is a string in go?
Beisdes that it is just a built in type
It's immutable.
It supports UTF-8, which means, it supports all the world languages.
- The difference between an array and a slice?
Array is fixed size and slices are dynamic which use arrays under the hood, so you can add as many values as you want.
- How do you catch a panic?
By using recover.
Although keep in mind that the recover has to be inside of a deferr func.
Since the panic stops the execution, defer is executed if there is a panic.
//... rest of the code
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r)
}
}()
//... rest of the code
Normally libraries handle panics in their internal code, but they should always return proper error, so you should never get a panic from modules.
- What is the difference between any and interface{}
There is no difference.
any
is an alias for interface{}
Thanks for your attention.
Is there anything you would add?
Top comments (0)