“función de flecha js vs función” Código de respuesta

función normal vs flecha función en JavaScript

// Normal Function
let add = function (num1, num2) {
return num1 + num2;
}

// Arrow Function
let add = (num1, num2) => num1 + num2;
madhav

Declaración de la función de JavaScript vs flecha

Regular functions created through function declarations / expressions are both constructible and callable. ... Arrow functions (and methods) are only callable i.e arrow functions can never be used as constructor functions. Hence, they can never be invoked with the new keyword.
Fragile Frog

Función de flecha vs función en JavaScript

// Arrow function vs function
// Function in JavaScript
function regular(){
  console.log("regular function");
}
regular(); //regular function

// Arrow Function
const arrow = () => console.log("Arrow function");
arrow(); //Arrow function
Chetan Nada

función de flecha js vs función

// currently common pattern
var that = this;
getData(function(data) {
  that.data = data;
});

// better alternative with arrow functions
getData(data => {
  this.data = data;
});
RedConcrete

FUNCIÓN DE ARROURA Sintaxis vs Function Expression Syntax

// Using function expression syntax
const addNums = function(numOne, numTwo) {
  return numOne + numTwo;
};

// Using new arrow function syntax
const addNums = (numOne, numTwo) => {
  return numOne + numTwo;
};
Graceful Gorilla

Respuestas similares a “función de flecha js vs función”

Preguntas similares a “función de flecha js vs función”

Más respuestas relacionadas con “función de flecha js vs función” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código