Computer scienceProgramming languagesGolangPackages and modulesStandard libraryContext package

Context package

Derived Context Values

Report a typo

At the end of the computation, what value will the variable result have?

type ctxKey string

rootCtx := context.Background()
nameKey := ctxKey("name")
ageKey := ctxKey("age")

alice := context.WithValue(rootCtx, nameKey, "Alice")
bob := context.WithValue(alice, nameKey, "Bob")
oldBob := context.WithValue(bob, ageKey, 120)

result := oldBob.Value(nameKey)
Enter a short text
___

Create a free account to access the full topic