//Revision Lecture 2: 25 Sep 2022
//Topic 2: //* JS functions *//
//A JavaScript function is a block of code designed to perform a particular task.
//task in function perform when called
function addition(x,y){
return x + y
}
let x1 = addition(10,20)
console.log(x1) // result --> 30
console.log(addition(100,200)) // result --> 300
function Ganit(x,y){
console.log(x+y)
console.log(y-x)
console.log(x*y)
console.log(y/x)
}
Ganit(30,60) // result --> 90, 30, 1800, 2
Ganit(50,100) // result --> 150, 50, 5000, 2
//Basic types of function
//1) without parameters and without return type
function add2(){
console.log(55+35)
}
add2() // result --> 90
//2) with parameters and without return type
function add3(f,g){
console.log(f+g)
}
add3(35,36) // result --> 71
//3) with parameters and with return type
function add4(f,g){
return f*g
}
console.log(add4(90,10)) // result --> 900
let c = add4(90,10)
console.log(c*2) // result --> 1800
// Ways of writing function
//1) function declaration
function sub(){
console.log(60-25)
}
sub() // result --> 35
//2) function expression
sub2 = function(){
console.log(100-25)
}
sub2() // result --> 75
//3) arrow function
sub3 = ()=>{
console.log(200-50)
}
sub3() // result --> 150
टिप्पण्या
टिप्पणी पोस्ट करा
आपल्या प्रतिक्रियेबद्दल धन्यवाद ! आम्ही लवकरात लवकर प्रतिक्रियेला उत्तर देण्याचा प्रयत्न करू