DekGenius.com
JAVASCRIPT
how to make a function
function myFunction(){
console.log('hi')
}
myFunction()
syntax function
function myFunction(a, b){
let calc = a + b;
return calc;
}
myFunction(5,3) // result= 8
function
function doSomething()
{
var x;
x = 10;
y = 20;
alert('x = ' + x);
alert('y = ' + y);
}
function
function factorial(n) {
if (n == 0) {
return 1;
} else {
return factorial(n - 1) * n;
}
}
function
function world(params){
//Code to be executed when the function is called.
}
world()
//Explaination
//'world' in the function is the name of the function.
//There are brackets after function name. Those are use to push parameters
//The forth line Calls the function named 'world'
function example
>>> def hello(name):
>>> print('Hello {}'.format(name))
>>>
>>> hello('Alice')
>>> hello('Bob')
Hello Alice
Hello Bob
Define function
function say(message) {
console.log(message);
}
let result = say('Hello');
console.log('Result:', result);
Code language: JavaScript (javascript)
function
#pip install danielutils
from danielutils import overload
class Foo:
def __init__(self):
pass
#'None' to skip
@overload(None, int)
def __add__(self, other):
return 1
@overload(None, str)
def __add__(self, other):
return 2
@overlaod(str,[int,float])
def bar(name,age):
return 3
@overload(str,str)
def bar(name,color):
return 4
if __name__ == '__main__':
print(Foo()+5) #-> 1
print(Foo()+"s") #-> 2
print(bar("jake",5)) #-> 3
print(bar("jake",5.5)) #-> 3
print(bar("jake","blue")) #-> 4
function
funcion name_of_funtion(){
}
function
function functionName(parameter1, parameter2, parameter3) {
body code goes here
}
/function
/function <name:unknown>
/function <name:string>
Function example
// Define a function that prints a stringfunction welcomeMessage() { console.log('Welcome to JavaScript');}// Call the functionwelcomeMessage();
function
A function is a set of statements that take inputs, do some specific
computation and produces output.
The idea is to put some commonly or repeatedly done task together and make a
function so that instead of writing the same code again and again for different
inputs, we can call the function.
function
function nama_function(parameter/argument 1, parameter/argument 2, ...) {
[Isi dari function berupa tindakan/steatment]
return [expression];
}
function
// function declaration
void greet() {
cout << "is it possible";
}
function
// function bilal(){
// console.log("bilal joyia")
// }
// bilal();
// function future(){
// console.log("developer")
// }
// future();
function
<type> function(parameter)
{
do this;
return value;
}
/*
int add(number1, number2)
{
return number1 + number2;
}
print(add(2,3));
*/
function
int main()
{
foo();
getchar();
return 0;
}
void foo()
{
printf("foo called");
}
© 2022 Copyright:
DekGenius.com