InterviewSolution
| 1. |
What are promises JavaScript? |
|
Answer» Recursion is a technique for iterating over an operation by having a function call itself repeatedly until it arrives at a result. Let consider the below simple example to add numbers from the CURRENT passed number BACKWARDS till 1. Say we pass 3, then 3+2+1 = 6. In the below example If(n≤0) is the termination condition and return n + add(n-1); is the recursion. The recursion works as shown in the diagram below. Now the add(2) will be called and will be expended into “2 + add(1)”. Finally the add(0) will trigger the termination condition If(n≤0) and produce 0. |
|