[Test] GoLang string type variable default value


Conclusion

Default value is “”.


Test Code

package main

import (
	"fmt"
)

type Student struct {
    Name string
}

func main() {
	var a Student
	fmt.Println("Hello, playground" + a.Name)
	
	if a.Name == "" {
		fmt.Println("Same")
	} else {
		fmt.Println("Not Same")
	}
	
	var testString string
	fmt.Println("Hello, playground" + testString )
	
	if testString == "" {
		fmt.Println("Same")
	} else {
		fmt.Println("Not Same")
	}
}

Test Result

test result

Leave a comment