DEV Community

PUSHAN VERMA
PUSHAN VERMA

Posted on

Functions in JavaScript

method-1
let name2="pushan";
function greet(name2 )
{
console.log(This is my name ->${name2});
}
greet(name2);

method-2
function greet2(name2,rollno)
{
console.log(This is my name ->${name2} and rollno ->${rollno});
}
greet2(name2,114);

method-3
function greet3(name2,rollno="114")
{
console.log(This is my name ->${name2} and rollno ->${rollno});
}
greet3(name2);
Image description

with return value
console.log("+++++++++++++++++++++++++++++++++++++++++");
let no=1;
const value =function(no)
{
let sum=0;
for(let i=1;i<10;i++)
{
sum+=no*2;
}
return sum;
}

console.log(value(no));
Image description

returning from objects
console.log("*****************************");
let obj2={
name3 :"pushanVerma",
rollno: 114,
techStack: function()
{
return {
java:"good",
mysql: "moderate",
javaScript:"Normal",

}
}
}

console.log(obj2.techStack());
Image description

Top comments (0)