Type stability and assignments of functions

This is slightly tricky. Defining a function like this implicitly makes f a const (when at global scope). Using const globals is totally fine for performance.

This assignment creates a new non-const variable named g with the same value as f. Your use of g within gg thus constitutes the use of a non-constant global variable, which is why type inference fails.

In global scope, you can do:

const g = f

In local scope (e.g. inside a function), you don’t need to worry about this at all.

5 Likes