Learn JavaScript
Lesson 1 - Introduction To JavaScript
Lesson 2 - Basic JavaScript Syntax
Lesson 3 - Control Flow
Lesson 5 - Basic Data Structures
Lesson 6 - Basic String Operations
Lesson 7 - Basic Array Operations
Lesson 8 - Exception Handling
Lesson 9 - Packages
Lesson 10 - User Input
Functions can also return values using the return
keyword. This allows the function to send data back to the code that called it.
function add(a, b) { return a + b; } console.log(add(3, 2));
In the above example, the function add()
adds a
and b
mathematically and returns the resulting value, which we print through console.log()
.
Let's create a function that solves the equation x + y - z
.
function solveEqu(x, y, z) { return add(x, y) - z; } // Function to add two numbers function add(x, y) { return x + y; } console.log(solveEqu(3, 5, 2));
Notice that the function solveEqu()
depends on the function add()
. This approach is known as the nested function where multiple functions are interconnected with each other.
Try to edit the code and apply a different equation.