File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments