+ 1
What is function
Help
8 Respostas
+ 5
these are blocks of code that perform a specific task.. and they can be reused anytime you wish to. .
example:
void helloWorld(){
System.out.println("Hello World");
System.out.println("This is a function");
}
then you can call this method anytime you want, and it will display;
'Hello World
This is a function'
+ 5
Functions make the code reusable.
+ 5
A function is simply a set of commands or tasks which are performed on being called.
A function is defined in a separate line or block of code; consider the following JS example:
function sum(s1, s2){
return s1 + s2;
}
In the above example, sum is the name of the function. The parentheses following it contains the list of parameters (or arguments) which are the variables whose values are passed on function call (in this case, the two numbers s1 and s2). It can be empty (no arguments) and only a blank set of parentheses will be used in such case.
Then, whenever required, the function is called:
var result = sum(3, 5);
OR
var a = 3, b = 5, result;
result = sum(3, 5);
The return statement is optional, depending on whether you want the function to return some value on being called.
+ 4
Reusable blocks of code for performing specific tasks
+ 4
Functions help keep the code concise and prevent the need to repeat statements in the code.
+ 2
It is a collection of statement(s) where you want it to be performing a specific task like for instance a keyboard is a collection of keys to input text data into a device the task is input so the keyboard can be used any time after it is declared useful... when writing instructions to a computing device then there are instructions you want to group together to work as a unit to archive a task or tasks so that's what is a function in many words
+ 2
They are simply blocks of code which can be used multiple times.
+ 1
The process of act known as function