JS-Function

Syntax of a function

function name(){}

Exemple

function showAdress)_{
document.write("Hello");
}

Function calling

showAdress();

Function and local variables

Variable declared in the body of a function
...{var custAdress}...

Argument - > passing an argument

This means: providing an argument to a function

function circleArea(radius){
var areas;
area=radius*radius*3.14;
document.write("area is: ",area);
}
circleArea(20.75);

function with more than one argument

function rectangleArea(length,height){
var area;
area=length*height*3.14;
document.write("area: ",area);
}
var length,height;
length=52.05;
height=46.55;
rectangleArea(length,height);

Argument with different types

function rectangleArea(length,height,shape){
....}
length=2;
height=4;
shape="rectangle";
rectangleArea(length,height,shape);

Returning a value

....
return area; }
producing a value and making it available to other functions

Comments

Popular posts from this blog

Programming- AI, machine learning

Programming -- JS, C, C++, Python

links - Robotic