Day 3 in JavaScript

Function:
• A function is a set of instructions with a name.
• Functions are reusable blocks of code designed to perform a particular task.
• Functions enable better code organization, modularity, and efficiency.
• They can be used to avoid repeating t…


This content originally appeared on DEV Community and was authored by VIDHYA VARSHINI

Function:
• A function is a set of instructions with a name.
• Functions are reusable blocks of code designed to perform a particular task.
• Functions enable better code organization, modularity, and efficiency.
• They can be used to avoid repeating the same code.

How to define a function:
• function is a reserved keyword.
• Syntax: function functionName(parameters) { // instructions }

Example:

function MakeBiriyani() {
set of instructions
}

Here, 'MakeBiriyani' is the function name and inside '()', the parameters can be given. This is to get the input for the function.
'{}' contains the set of instructions.

Example:

function sample() {
  console.log(typeof 1);
}
sample();

Here, the term 'typeof' will give the data type. It will return as "number".

Another example:

function sub(a, b) {
  console.log("sub: " + (a - b));
}
sub(12, 7);

Output: 5


This content originally appeared on DEV Community and was authored by VIDHYA VARSHINI


Print Share Comment Cite Upload Translate Updates
APA

VIDHYA VARSHINI | Sciencx (2025-08-06T02:34:23+00:00) Day 3 in JavaScript. Retrieved from https://www.scien.cx/2025/08/06/day-3-in-javascript/

MLA
" » Day 3 in JavaScript." VIDHYA VARSHINI | Sciencx - Wednesday August 6, 2025, https://www.scien.cx/2025/08/06/day-3-in-javascript/
HARVARD
VIDHYA VARSHINI | Sciencx Wednesday August 6, 2025 » Day 3 in JavaScript., viewed ,<https://www.scien.cx/2025/08/06/day-3-in-javascript/>
VANCOUVER
VIDHYA VARSHINI | Sciencx - » Day 3 in JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/06/day-3-in-javascript/
CHICAGO
" » Day 3 in JavaScript." VIDHYA VARSHINI | Sciencx - Accessed . https://www.scien.cx/2025/08/06/day-3-in-javascript/
IEEE
" » Day 3 in JavaScript." VIDHYA VARSHINI | Sciencx [Online]. Available: https://www.scien.cx/2025/08/06/day-3-in-javascript/. [Accessed: ]
rf:citation
» Day 3 in JavaScript | VIDHYA VARSHINI | Sciencx | https://www.scien.cx/2025/08/06/day-3-in-javascript/ |

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.