To var or not to var my javascript

This is probably trivial to a lot of people. I’ve done a bit of javascript work recently and in looking at reference material and code snippets around the internet, I noticed that the ‘var’ keyword to declare a variable seems to be optional in all cases. Even popular libraries, like Script.aculo.us, have revisions where ‘var’ appears where it wasn’t in the previous release.

In your own coding there’s two things to keep in mind about it.

  1. For global variables, it doesn’t matter, but you may want to use it for consistency.
  2. Always try to use ‘var’ to declare variables in local functions. It makes sure you’re using a local copy of the variable instead of another variable of the same name in a different scope.

For example, the two similar functions here have very different effects:

var myvar = 0;
function affectsGlobalVar(i){
   myvar = i;
}
function doesNotAffectGlobalVar(i){
   var myvar = i;
}

What categories should I use for my site?

As I’m finishing up this site, one thing I’ve gone back and forth on is what categories I should create. How specific do they really need to be? For example, If I write an article on how to create some nifty do-dad in PHP, would a Code category be okay, or should I have a PHP category. Both?

After thinking about it for a little, I decided to go to a few blogs I frequent and see what categories they use. Maybe I should be consistent with what others are doing. I’m not sure how many people really make use of categories, but maybe consistency would be important.

What I found is that there isn’t too much commonality in category naming. Some people use a lot, others not. It’s obviously dependent upon the type of blog.

One interesting thing I found out was that a number of sites had categories listed with no articles attached to them. Therefore, I decided to just start with nothing and create categories as I go. I’m sure I’m not the first person to do it this way, but it just didn’t occur to me right away.

More Articles

Page 9 of 9 » ‹ First  < 7 8 9