Functions are statements that perform some tasks. We define function using function keyword. Then we name the function and open curly braces{}, in which the statements are written. A function performs the task when we βcallβ it.
Example:
function age(x){
alert(x " years old")
}
if we write
age(19)
A window will be opened in which will be written
19 years old.
The function receives what are written in the brackets. It do the the operations with the arguments which were given and returns us the final result. We can create function once and reuse it. We can call it every time with different arguments and get different results. The variables which are declared inside the function are not visible outside the function. There also exists function composition. We can have functions inside functions.
Top comments (0)