1//(don't type behind the// type function to after that name it//
2function name() {
3 (name)=name
4 console.log(name)
5};
6//{ symbol is used o group together code but you must create n index/array of 2(array3)//
1//1st (simple function)
2function hello1() {
3 return "Hello simple function";
4}
5
6//2nd (functino expression)
7hello2 = function() {
8 return "Hello functino expression";
9}
10
11// 3rd ( IMMEDIATELY INVOKED FUNCTION EXPRESSIONS (llFE))
12hello3 = (function() {
13 return "Hello IMMEDIATELY INVOKED FUNCTION EXPRESSIONS (llFE)";
14}())
15
16//4th (arrow function)
17hello4 = (name) => { return ("Hello " + name); }
18 //OR
19hello5 = (name) => { return (`Hello new ${name}`) }
20
21document.getElementById("arrow").innerHTML = hello4("arrow function");
22
23document.write("<br>" + hello5("arrow function"));
1// Code by DiamondGolurk
2// Defining the function
3
4function test(arg1,arg2,arg3) {
5 // Insert code here.
6 // Example code.
7 console.log(arg1 + ', ' + arg2 + ', ' + arg3)
8}
9
10// Running the function
11
12test('abc','123','xyz');
13
14// Output
15// abc, 123, xyz
1// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2// FUNCTION DECLARATION (invoking can be done before declaration)
3// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4function calcAge1(birthYear) {
5 return 2037 - birthYear;
6}
7const age1 = calcAge1(1991);
8
9// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10// FUNCTION EXPRESSION (invoking canNOT be done before declaration)
11// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12const calcAge2 = function (birthYear) {
13 return 2037 - birthYear;
14}
15const age2 = calcAge2(1991);
16
17// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18// ARROW FUNCTION (generally used for one-liner functions)
19// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20const calcAge3 = birthYear => 2037 - birthYear;
21const age3 = calcAge3(1991);
22console.log(age3);