#Day62 of learning #javascript from scratch... click on the tweet to view full content. Today we will learn to Use Recursion to Create a Range of Numbers
The value [1, 2, 3, 4, 5] will be displayed in the console.
At first, this seems counterintuitive since the value of n decreases, but the values in the final array are increasing.
This happens because the push happens last, after the recursive call has returned. At the point where n is pushed into the array, countup(n - 1) has already been evaluated and returned [1, 2, ..., n - 1].
#Day60 of learning #javascript from scratch... click on the tweet to view full content. Today we will learn to Use Multiple Conditional (Ternary) Operators
It is considered best practice to format multiple conditional operators such that each condition is on a separate line, as shown above. Using multiple conditional operators without proper indentation may make your code hard to read. For example:
The following function uses an if/else statement to check a condition:
function findGreater(a, b) {
if(a > b) {
return "a is greater";
}
else {
return "b is greater or equal";
}
}