For example, will the first piece of code perform a full search twice, or is it smart enough to cache results if no DOM changes have occurred?
if ($("#navbar .heading").text() > "") {
$("#navbar .heading").hide();
}
and
var $heading = $("#navbar .heading");
if ($heading.text() > "") {
$heading.hide();
}
If the selector is more complex I can imagine it's a non-trivial hit.