JavaScript Functions Explained: Declarations, Expressions, and More

🚀 JavaScript Functions — Explained Functions are the backbone of JavaScript What is a Function? >> A function is a reusable block of code designed to perform a specific task.  1. Function Declaration:  A function defined using the function keyword with a name. function greet(name) {  return "Hello " + name; } ✔️ Hoisted (can be used before declaration)  2. Function Expression:  A function stored inside a variable. const greet = function(name) {  return "Hello " + name; }; ❌ Not hoisted like declarations  3. Arrow Function:  A shorter syntax for writing functions using =>. const greet = (name) => "Hello " + name; ✔️ Clean and concise ⚠️ Does not have its own this  4. Parameters: Variables listed in the function definition. function add(a, b) { } >> a and b are parameters  5. Arguments: Actual values passed to a function when calling it. add(2, 3); >> 2 and 3 are arguments 6. Return Statement:  The return keyword sends a value back from a function and stops execution. function add(a, b) {  return a + b; }  7. Callback Function: A function passed as an argument to another function. function greet(name) {  console.log("Hello " + name); } function processUser(callback) {  callback("Javascript"); }  8. Higher-Order Function:  A function that takes another function as an argument or returns a function. >> Examples: map(), filter(), reduce()  9. First-Class Functions:  In JavaScript, functions are treated like variables. ✔️ Can be assigned to variables ✔️ Can be passed as arguments ✔️ Can be returned from other functions #JavaScript #WebDevelopment #FrontendDevelopment #Coding #Programming #LearnToCode

To view or add a comment, sign in

Explore content categories