Returning the value of navbarHeight rather than setting it as a global removes the need for the variable. 
The function body could read:

return (window.innerWidth >= 840) ? $('.navbar').height() : 0;