I was looking to this post Wrap up javascript global variables,
var Global_VARS = {
productId:10,
itemId:20,
commentId:30,
ratingId:20
}
Is this a good way of writing JavaScript variables?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The general rule you should always follow is to not clutter the Global namespace with global variables.
So you should keep the global variables as low as possible to avoid cluttering. Grouping all your variables in one unique object is a good idea rather than having them global.
Having them inside an anonimous function is also good, inside a function you can have as many variables as you want, they won’t be avaiable externally. Then you can choose which one will be avaiable to the outside.