What is the reason for offset.top not work without var of element

What is the reason for offset.top not work without var of element
0

#1

This one work

var $test = $('#test');
var $testoffset = $test.offset().top;

but with without var for element #test

$('#test').offset().top;

Not work? What the logic behind this?


#2

Without the var keyword, this would create a global variable, which can cause many problems.


#3

Thanks!

Still a question with when use .scroll function with jquery that default what is inside is script that is global? I try with .each function and there only works var inside it what used in .each function when outside its not work. So basicly functions in jQuery all global or local like .each?

Thanks