JavaScript Functions: Named, Anonymous, and Arrow Functions

𝗣𝗹𝗮𝘆𝘄𝗿𝗶𝗴𝗵𝘁 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 & 𝗧𝘆𝗽𝗲𝗦𝗰𝗿𝗶𝗽𝘁 – 𝗗𝗮𝘆 𝟵 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀  A function is a reusable block of code designed to perform a specific task. 𝗲𝘅: function greet() {  console.log("Hello World"); } 𝟭. 𝗡𝗮𝗺𝗲𝗱 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 A function with a specific name. Reusable and easier to debug. 𝗲𝘅: function greet(name) {  return "Hello " + name; } console.log(greet("Jay")); 𝟮. 𝗔𝗻𝗼𝗻𝘆𝗺𝗼𝘂𝘀 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 A function without a name. Usually assigned to a variable or used as a callback. 𝗲𝘅: function run(greet: (name:String) => void ) : void { greet ("Prakash");  } 𝟯. 𝗔𝗿𝗿𝗼𝘄 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 Introduced in ES6. Shorter syntax and widely used in modern development. 𝗲𝘅: const greet = name => "Hello " + name; Follow me for regular insights on 𝗣𝗹𝗮𝘆𝘄𝗿𝗶𝗴𝗵𝘁 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻 𝗧𝗲𝘀𝘁𝗶𝗻𝗴. #JavaScript #TypeScript #NodeJS #Playwright #AutomationTesting #SoftwareTesting #QA #LearningInPublic #TestAutomation

To view or add a comment, sign in

Explore content categories