javascript: define a variable if it doesn't exist
Pro style:
var SomeVar = SomeVar || 'Default Value';
if (typeof variable === 'undefined') {
// variable is undefined
// eg:
// var variable = "someValue";
}
It would be a good coding practice in this case to use the ternary operator. Also you don't need to have three equal signs when comparing with typeof. This is the most concise solution:
b = typeof(b) == 'undefined' ? 0 : b;
This hopefully will save your hands some time.