First of all to all sp forum users Hello , im new tot this forum

I have a question about variable scope of JQuery. I have used the search function first but it still doenst really make sence to me how variable scope works, and when to use var in front of a variable.

can someone tell me how :
when or why to use var in front of variable?
how i can acces a variable in a function ?