What is a Function? Simple Explanation with Examples
what is function ? 1.function is a block of code that perform specific task. *block of code is a group of instruction to perform specific task. 2.Instead of writing the same code again and again, you can write it once inside a function and reuse it whenever needed. EXAMPLES; function square(number) { return number * number; } *In this case function is keyword, square is the function name what we named, inside the parentheses have parameters if we want to use so many parameters inside the parentheses then we must separate each of them with commas. *if we want to execute this function, then we should call this name of function, this function name is square so we call this like square() or if we want to put arguments then we should call this like square(23) in this case what was happened is y
what is function ?
1.function is a block of code that perform specific task. block of code is a group of instruction to perform specific task. 2.Instead of writing the same code again and again, you can write it once inside a function and reuse it whenever needed.
EXAMPLES;
function square(number) { return number * number; }*
In this case function is keyword, square is the function name what we named, inside the parentheses have parameters if we want to use so many parameters inside the parentheses then we must separate each of them with commas.
if we want to execute this function, then we should call this name of function, this function name is square so we call this like square() or if we want to put arguments then we should call this like square(23) in this case what was happened is you imagine number(parameter) is the variable and arguments is variable value , what the value(arguments) we give while callback that value will store in variable(parameters)
for example: let calculation = square(2) --- => this returned number * number console.log (calculation) Then final output is --- 4 (22 --- => numbernumber)*
Inside calculation have function that entire function returned (number * number) right then we print the variable calculation then output is 4 because my arguments is 2*2 =>4
REFERENCE WEBSITE; https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions
DEV Community
https://dev.to/subash_4870e66d76ac024544/what-is-a-function-simple-explanation-with-examples-2f50Sign in to highlight and annotate this article

Conversation starters
Daily AI Digest
Get the top 5 AI stories delivered to your inbox every morning.
Knowledge Map
Connected Articles — Knowledge Graph
This article is connected to other articles through shared AI topics and tags.
More in Products
Chicken-Free Egg Whites
Baking has traditionally made extensive use of egg whites, especially the way they can be beaten into a foam and then set with heat. While I eat eggs, I have a lot of people in my life who avoid them for ethical reasons, and this often limits what I can bake for them. I was very excited to learn, though, that you can now buy extremely realistic vegan egg whites! EVERY engineered yeast to convert sugar into ovalbumin , the main protein in egg whites and the one responsible for most of its culinary function. This kind of fermentation was pioneered for insulin and microbial rennet in the 1980s, but many companies are now applying it to producing all kinds of vitamins, proteins, dyes, and enzymes. EVERY has been working with commercial customers for several years, but you can now buy it as a s




Discussion
Sign in to join the discussion
No comments yet — be the first to share your thoughts!