July 2016
Intermediate to advanced
274 pages
6h 11m
English
Let's consider an extremely simple example and see how the (somehow) specialized modular approach differs from a non-modular one.
We start by writing a couple of functions in the traditional way, as following:
function doAddition(num1, num2){
return num1 + num2;
}
function doSubtraction(num1, num2){
var result = null;
if(num1 > num2){
result = num1 - num2;
}else{
result = num2 - num1;
}
return result;
}
console.log(doAddition(3,2)); // displays 5
console.log(doSubtraction(3,2)); // displays 1As you can see in the above code, we have two independent functions for doing simple additions and subtractions and there is no relation between the two, other than the fact that they both operate on the two passed-in numbers ...
Read now
Unlock full access