No, your function should use the return keyword to return a value. Right now you’re logging a value to the console, then returning undefined implicitly.
var works but for all intents and purposes it’s a legacy feature that only exists for backwards compatibility with programs that were written when it was the only choice. In modern code you should avoid using var because it has some strange behaviors that can be difficult to debug when you run into them (in this specific case it didn’t matter).
So basically, don’t use var. Use const by default, use let when you need it.