Hoisting: ========= var, let and const ==> The variable can be extract to the above declaration. log(x) ==> Undefined x = 12 console.log("Hi"); console.log(x); console.log(y); // console.log(z); // console.log(p); console.log("Good Evening."); var x; // declaration of variable var y = 1122; const z = 123; let p; console.log(x); console.log(y); console.log(z); console.log(p); Functions: ========== methods Vs functions: ===================== void main(String[] args) { // method body } void function_name(d1,d2,d3,...) { // function body } class{ function definition ==> method } function definition ==> function class{ } what is the function? ===================== function is the named block which is defining with group of statements to perform the specific task. ==> function can accept the data ==> function can return the data How to define the function? =========================== keyword: function Syntax: function definition function nameOfFunction(parameters/arguments with comma separation) { // block of statements // specify the task to implement // returning statement } ==> to make the function required to perform some task, it must be call. (function call) Syntax: function-name(values for the parameters) Identifiers: case of alphabets: lower case upper case Title Case Capitalize case Camel Case JavaFullstack ==> Capitalize Case javaFullstackDev ==> Camel Case Javafullstack ==> Title case ========================== // WAP IN JS TO CREATE THE FUNCTION CAN USE TO DISPLAY THE GREETINGS. // function with zero parameters function myFunction() { console.log("Hello all."); console.log("Good Evening."); } myFunction(); ======================================= // Function with parameters =========================== function sumOfNumbers(a,b,c,d) { var sum = a+b+c+d; console.log("The Sum of Four numbers = "+sum); } sumOfNumbers(10,20,30,40,50); ==================================== // WAP IN JS TO CREATE A FUNCTION TO DISPLAY THE MULTIPLICATION TABLE FOR ANY NUMBER. function multiplicationTable(num) { for(i = 1;i <= 10;++i) { console.log(num+" X "+i+" = "+(num * i)); } } multiplicationTable(8); ======================================= How the function can return a value: ==================================== return: ======= Syntax: return variable; function sumOfDigits(num) { var n = num; let sum_dig = 0; while(n != 0) { var ind_dig = n % 10; sum_dig += ind_dig; n = Math.floor(n/10); } return sum_dig; } var result = sumOfDigits(112233); console.log("The Sum of Digits = "+result); console.log("The Sum of Digits = "+sumOfDigits(987654321)); ========================================== function addition(a,b) { return a + b; } function subtraction(a,b) { if(a > b) { return a -b; } else{ return b-a; } } function multiplication(a,b) { return a * b; } console.log("The Sum = "+addition(15,45)); console.log("The DIfference = "+subtraction(25,35)); console.log("The Product = "+multiplication(23,25)); ==================================== Assignment: =========== 1) WAP TO CREATE THE FUNCTIONS TO CHECK THE TYPE OF TRIANGLE AND CALCULATE THE AREA OF THE TRIANGLE. 2) WAP TO FIND THE FACTORIAL OF THE NUMBER BY CREATING THE FUNCTION. 0! = 1 <0 ==> no factorial is possible >0