Functions in JavaScript.

1. Introduction
Function is a block of code which perform specific task in a better and efficient way.

Syntax
It is defined using function keyword, then followed by the name of the function say var1, followed with parentheses ().
Function name follo…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Keshav Jindal

1. Introduction
Function is a block of code which perform specific task in a better and efficient way.

Syntax
It is defined using function keyword, then followed by the name of the function say var1, followed with parentheses ().
Function name follows same rules as of variable name.

function var1(par1, par2) {
code to be executed
}

2. Uses of Functions
Functions basically resist the repetition of same code again and again. Once the code is designed, we can use it multiple times just by giving the
arguments.

Example:

function add(num1, num2) {
  const addition = num1 + num2;
  console.log(addition);
}
add(2, 1);
add(63,232):

Output:
3
295
3. Function Return
When return keyword is used in Function and it reaches to return statement, the code will stop executing. Return keyword helps in future use of the output of Function.

For example:

function multi(par1, par2) {
  return par1 * par2;
}
console.log(multi(10, 2));


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Keshav Jindal


Print Share Comment Cite Upload Translate Updates
APA

Keshav Jindal | Sciencx (2022-11-05T13:37:46+00:00) Functions in JavaScript.. Retrieved from https://www.scien.cx/2022/11/05/functions-in-javascript-6/

MLA
" » Functions in JavaScript.." Keshav Jindal | Sciencx - Saturday November 5, 2022, https://www.scien.cx/2022/11/05/functions-in-javascript-6/
HARVARD
Keshav Jindal | Sciencx Saturday November 5, 2022 » Functions in JavaScript.., viewed ,<https://www.scien.cx/2022/11/05/functions-in-javascript-6/>
VANCOUVER
Keshav Jindal | Sciencx - » Functions in JavaScript.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/05/functions-in-javascript-6/
CHICAGO
" » Functions in JavaScript.." Keshav Jindal | Sciencx - Accessed . https://www.scien.cx/2022/11/05/functions-in-javascript-6/
IEEE
" » Functions in JavaScript.." Keshav Jindal | Sciencx [Online]. Available: https://www.scien.cx/2022/11/05/functions-in-javascript-6/. [Accessed: ]
rf:citation
» Functions in JavaScript. | Keshav Jindal | Sciencx | https://www.scien.cx/2022/11/05/functions-in-javascript-6/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.