Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

normal function vs arrow function in javascript

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

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

javascript function declaration vs arrow function

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.
Comment

arrow function vs function in 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
Comment

js arrow vs normal function

// jsdrops.com/arrow-functions

this.whoIsThis = 'TOP'; // Identify this scope

// 1) Defining
const fancyObj {
  whoIsThis: 'FANCY', // Identify this object
  regularF: function () {
    console.log('regularF', this.whoIsThis);
  },
  arrowF: () => {
    console.log('arrowF', this.whoIsThis);
  },
};

// 2) Calling
console.log('TOP-LEVEL', this.whoIsThis); // It's "TOP" here

fancyObj.regularF(); // Output #1 (Fancy)
fancyObj.arrowF();   // Output #2 (Top)

fancyObj.regularF.call({whoIsThis: 'FAKE'}); // Output #3 (Fake)
fancyObj.arrowF.call({whoIsThis: 'FAKE'});   // Output #4 (Top)
Comment

js arrow function vs function

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

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

PREVIOUS NEXT
Code Example
Javascript :: will console.log will be automatically disabled in react native for development build 
Javascript :: * ws in ./node_modules/puppeteer/lib/WebSocketTransport.js 
Javascript :: onclick remove textarea value 
Javascript :: check if browser is online 
Javascript :: Century From Year 
Javascript :: image load fail event html 
Javascript :: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.6/$injector/modulerr?p0=myApp 
Javascript :: can we use setstate inside build 
Javascript :: js currency converter 
Javascript :: what is the use of useparams in react 
Javascript :: javascript create object from key value pairs 
Javascript :: Kendo Grid export to Excel not working with large data 
Javascript :: js closure 
Javascript :: jquery public function 
Javascript :: vue 3 $refs 
Javascript :: joi number of digits 
Javascript :: array destructuring by using spread operator from a nested object in javascript 
Javascript :: react node-sass 
Javascript :: moyenne javascript 
Javascript :: js number to string 
Javascript :: Regex for number divisible by 5 
Javascript :: make alphabet js 
Javascript :: get contents between tags javascript 
Javascript :: mongoose read 
Javascript :: chess.js 
Javascript :: react firebase add doc to collection 
Javascript :: javascript redirect to file 
Javascript :: js extract boolean from string 
Javascript :: Repeat a String Repeat a String-Javascript 
Javascript :: node js arabic number to english number 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =