-
Types Of Function In Javascript
Here are different methods to write functions:
1. Function declaration:
function declaration are not executed immediately mean to say hum jb tk inn ko call nhi karein gy ye execute nhi ho gy. Iss mein humre pas function keyword ata hai jo javascript mein function ko declare krta hai, fir function ka name atta hai jis ki madad say hum function ko call krte hain.Syntax:
function function_name(parameter1, parameter2) {
Your Code…..
}2. Function expression:
function expression mein function ko as a variable store kiya jta hai iss lye iss type mein hum function ko run krne kay lye variable ko call krte hain. Function expressions are often used where functions are assigned to variables.Syntax:
const x = function () {
return 2 * 5
};3. Anonymous function:
The function without any name is anonymous function mean to say jase function expression mein hum nay function ko variable mein store kiya toh wahan function ko name nahi diya balkay
call krne kay lye variable ka name use kiya tah toh wo anonymous function howa. Iss ki aik or example iss tarah hai jb hum addEventListener use kr kay function pr event ko call ko krte
hain toh uss ka syntax kuch asaa hota hai.
document.getElementsById(‘demo’).addEventListener(‘click’, function());
Yahan pr function ko name kay bagair define kiya howa hai toh ye bhi anonymous function howa. Iss ka use case hum tb krtein hain jb humko function aik hii barr use krna ho.4. Arrow Function:
Arrows function just apky code ko short krne kay lye use hota.Syntax:
const x = (x, y) => {
x * y
};
#xalfi
About Me
Rohama Salfi
Student
Hello! I'm Rohama Salfi, a student studying in Sg-Educate Institute, With a passion for developing websites. I was born and raised in Faisalabad. I completed my middle from Allied School, matric from Govt Pilot School and intermediate from Eduacators College. Beyond my professional life, I am passionate about photography, editing, playing basket ball. Beyond this all am risk-taker, adventurer, philosopher, narcissistic person. Feel free to connect with me on email rohxama@gmail.com. I'm always open to discussions and sharing insights with like-minded individuals. Thank you for taking the time to learn a bit about me.
Groups
Web Development
Private Group