Skip to content

Commit d35c947

Browse files
committed
Added Functions in JS
1 parent b294064 commit d35c947

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

functions.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Functions
2+
-- Functions are one of the fundamental building blocks in JavaScript. A function is a reusable set of statements to perform a task or calculate a value.
3+
Functions can be passed one or more values and can return a value at the end of their execution. In order to use a function, you must define it somewhere in the scope where you wish to call it.
4+
5+
The example code provided contains a function that takes in 2 values and returns the sum of those numbers.
6+
7+
// Defining the function:
8+
function sum(num1, num2) {
9+
return num1 + num2;
10+
}
11+
12+
// Calling the function:
13+
sum(3, 6); // 9
14+
15+
16+
-- Function Parameters
17+
Inputs to functions are known as parameters when a function is declared or defined.
18+
Parameters are used as variables inside the function body. When the function is called, these parameters will have the value of whatever is passed in as arguments.
19+
Note: It is possible to define a function without parameters.
20+
21+
// The parameter is name
22+
function sayHello(name) {
23+
return `Hello, ${name}!`;
24+
}

0 commit comments

Comments
 (0)