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

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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.