Lädt...


🔧 Draft: What are the differences between arrow functions and traditional functions?


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

The Javascript traditional functions have some superpowers instead of simple arrow functions because normal functions follow the Javascript prototype pattern and do not have access to the magic keywords “this” where we can control the function context.

I show below some powers of JS normal functions:

  • Using functions as constructors:

    As an arrow, you will get an error:

      const Person = (name) => {
        this.name = name;
      };
    
      const person = new Person("John");
    

    The error we get:

    Image description

    Using a normal function:

    function  Product(title, price){
      this.title  =  title;
      this.price  =  price;
    }
    
    let  p1  =  new  Product("Pen",100);
    
    console.log(p1);
    

    As a result we will get:

    Image description

  • Having access to "arguments" of the context:

      function myFunc() {
        console.log(arguments);
      }
    
      myFunc(1, 'text', 5, 6); // Logs [1, 'text', 5, 6
    
  • Having their own access to this context:

      const person = {
        value: 'I used normal functions',
        showTheValue: function() {
          setTimeout(function() {
            console.log(this.value); // "this" refers to obj
          }, 1000);
        }
      };
    
      person.showTheValue(); // Logs "I used normal functions"
    

    Using arrow functions:

      const person = {
        value: 'arrow function',
        showTheValue: () => {
          setTimeout(() => {
            console.log(this.value); // "this" does not refer to obj
          }, 1000);
        }
      };
    
      obj.showTheValue(); // Logs undefined or throws an error depending on strict mode
    

Conclusion:

Arrow functions are more concise and straightforward focused only on creating a function that executes a piece of code, normal functions can be used to solve a lot of problems in different ways not only to execute a piece of code.

...

🔧 Draft: What are the differences between arrow functions and traditional functions?


📈 86.46 Punkte
🔧 Programmierung

🔧 7 Differences Between Arrow Functions and Traditional Functions


📈 70.6 Punkte
🔧 Programmierung

🔧 The difference between Arrow functions and Normal functions in JavaScript


📈 42.35 Punkte
🔧 Programmierung

🔧 Pratical Differences between GCP Cloud Functions and AWS Lambda Functions


📈 40.94 Punkte
🔧 Programmierung

🔧 Tìm Hiểu Về RAG: Công Nghệ Đột Phá Đang "Làm Mưa Làm Gió" Trong Thế Giới Chatbot


📈 39.48 Punkte
🔧 Programmierung

🔧 Differences between arrow function and regular function in JavaScript


📈 38.4 Punkte
🔧 Programmierung

🔧 JavaScript Regular/Normal vs Arrow Function: My Beef with Arrow Functions.


📈 37.85 Punkte
🔧 Programmierung

🔧 Why the "this" Keyword Behaves Differently in Regular Functions and Arrow Functions


📈 33.43 Punkte
🔧 Programmierung

🔧 🚀 JavaScript Functions: Arrow Functions, Callbacks, and Closures 📜


📈 33.43 Punkte
🔧 Programmierung

🔧 Arrow Functions vs. Regular Functions in JavaScript: A Comprehensive Guide


📈 31.81 Punkte
🔧 Programmierung

🔧 JavaScript Arrow Functions vs Regular Functions


📈 31.81 Punkte
🔧 Programmierung

🔧 Mastering JavaScript Functions: Your Guide to Normal vs. Arrow Functions


📈 31.81 Punkte
🔧 Programmierung

🔧 Arrow Functions vs. Regular Functions in JavaScript: A Showdown


📈 31.81 Punkte
🔧 Programmierung

🔧 Understanding Arrow Functions vs. Normal Functions in JavaScript


📈 31.81 Punkte
🔧 Programmierung

🔧 Differences between Ethereum’s send/transfer/call functions


📈 30.73 Punkte
🔧 Programmierung

🔧 DevOps vs. Traditional: Key Differences in Software Development and Delivery


📈 29.87 Punkte
🔧 Programmierung

📰 Arrow ECS lädt zur »Arrow University«


📈 29.26 Punkte
📰 IT Security Nachrichten

🕵️ arrow-kt Arrow up to 0.8.x Gradle Build Artifact Resolver weak encryption


📈 29.26 Punkte
🕵️ Sicherheitslücken

📰 Channel-Treff in München: Arrow veranstaltet Arrow University - channelpartner.de


📈 29.26 Punkte
📰 IT Security Nachrichten

📰 Arrow Forum 2024: Arrow feiert ein großes Familienfest - channelpartner.de


📈 29.26 Punkte
📰 IT Security Nachrichten

🔧 Functions of Commercial Bank: Primary Functions and Secondary Functions


📈 27.38 Punkte
🔧 Programmierung

📰 Jibrel Network Is Bridging The Gap Between Crypto And Traditional Markets


📈 25.57 Punkte
📰 IT Security Nachrichten

📰 Honeycomb Metrics bridges the gap between traditional debugging practices and modern systems


📈 25.57 Punkte
📰 IT Security Nachrichten

🐧 What are the differences between Nix and Guix? Which one do you prefer and why?


📈 25.38 Punkte
🐧 Linux Tipps

🐧 What are the differences between Nix and Guix? Which one do you prefer and why?


📈 25.38 Punkte
🐧 Linux Tipps

🕵️ Similarities and differences between MuddyWater and APT34


📈 25.38 Punkte
🕵️ Hacking

matomo