Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I store my javascript variables?

I am currently coding in this way:

<script type="text/javascript">
var linkObj;

Is this a safe way to store data? My concern is what if a jQuery or other plug-in was to also use the variable linkObj. Also if I declare my variable like this then can it also be seen by other functions in scripts located in other js files that I include?

like image 438
Samantha J T Star Avatar asked Dec 10 '22 02:12

Samantha J T Star


1 Answers

$(document).ready(function(){
   var linkObj;

});

as long as you use the var keyword, any variable defined in that scope won't be accessible by other plugins.

like image 177
driangle Avatar answered Dec 11 '22 14:12

driangle