Type assertion in Go

Type assertion in Go safely extracts a concrete value from an interface variable using the comma-ok idiom to prevent panics.

Type assertion in Go extracts the concrete value from an interface variable by checking if it holds a specific type. Use the comma-ok idiom to safely handle cases where the type does not match without causing a panic.

if val, ok := myInterface.(string); ok {
	fmt.Println("It is a string:", val)
} else {
	fmt.Println("Not a string")
}