jQuery: Novice to Ninja => I'm not understanding why this does/doesn't work

On page 77 of jQuery: Novice to Ninja they have the following excerpt;
var $window = $(window).
$navigation = $(“#navigation”);

What I cannot for the life of me is figure out why it ONLY works if I have $window instead of window.

// This would not work
var window = $(window),
navigation = $(‘#navigation’);

window.scroll(function() {
navigation.css(‘top’, $(document).scrollTop());
});

// This will work
var $window = $(window),
navigation = $(‘#navigation’);

$window.scroll(function() {
navigation.css(‘top’, $(document).scrollTop());
});

Can someone help me understand why? I’ve read where preceding a var with the $ is common practice if the variable contains a jQuery object, but why will the window object only work if I precede the variable with the $?

I have a JSFiddle here: http://jsfiddle.net/ryentzer/3hAvm/

Scratching head,
Rick

Hi Rick,

window is a built-in browser object, so I would suspect that the browser won’t allow you to reassign it.

Thanks, that is exactly what it was. I was getting hung up, thinking that the $ in front of the variable name was causing some jQuery magic. What I should have done is tested with a random name to clue me in. I couldn’t see the forest through the trees so-to-speak.