I'm new to Objective javascript even I had a good amount of experience in Javascript. How do I pass my parameters to the calc closure here?
var calc = (function() {
var a = 5;
var b = 0;
return {
add: function() {
return a + b;
},
subtract: function() {
return a - b;
},
multiply: function() {
return a * b;
},
divide: function() {
if (b != 0) return a / b
else {
alert('division by zero');
return false;
}
}
}
})();
console.log(calc.divide());
I want to pass the parameters to calc like (calc.multiply(10,20));
Thanks in advance..
NaNin cases of division by zero. But, if you are intending the explicit validation, I suppose the alert is fine.