Is "var" necessary?

Is “var” necessary when assigning objects to variable names? I’ve seen it used at times and not used in other times. When are the implications of using/not using it?

For example:
exp = db.people.explain()
-versus-
var exp = db.people.explain()

It’s not mandatory. When you hit the Return key, the former returns the result and the latter doesn’t. Both will variables will be assigned.

1 Like