Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

arrow functions=>

// Traditional Anonymous Function
function (a, b){
  return a + b + 100;
}

// Arrow Function
(a, b) => a + b + 100;

// Traditional Anonymous Function (no arguments)
let a = 4;
let b = 2;
function (){
  return a + b + 100;
}

// Arrow Function (no arguments)
let a = 4;
let b = 2;
() => a + b + 100;
Comment

arrow function

const doSomething = () => {
  // Function Scope
};
Comment

An Arrow Function

/*The arrow functions were introduced in ECMA 2015 with the main purpose of giving a shorter syntax to a function expression. 
Besides providing shorter syntax, which increases the readability of the code, 
it does not have its own value of the this object. The value of this object inside an arrow function is inherited from the enclosing scope.

You can write an arrow function to add two numbers as shown in the next code example.*/

var add = (num1, num2)=> num1+num2; 
let res = add(5,2);
console.log(res); // 7 
Comment

arrow function

const = newfunc =(a,b)=>{
	return a+b
}
Comment

shorthand arrow function

const = newfunc = (a,b)=> a+b
Comment

arrow function

const hello = () => {  
 return 'Hello'
}

const hello = () => 'Hello'
console.log(hello())
Comment

arrow functions=>

(param1, paramN) => {
   let a = 1;
   return a + param1 + paramN;
}
Comment

arrow function

const bk = () =>{
   console.log("Bk function called");
}
bk()
Comment

arrow functions=>

// Traditional Anonymous Function
function (a, b){
  let chuck = 42;
  return a + b + chuck;
}

// Arrow Function
(a, b) => {
  let chuck = 42;
  return a + b + chuck;
}
Comment

Arrow Function Shorthand javascript

// Arrow Functions Shorthand javascript
// Longhand:
function sayHello(name) {
  console.log('Hello', name);
}
sayHello("Chetan"); // Hello Chetan

setTimeout(function() {
  console.log('Loaded'); //Loaded
}, 2000);

[1,2,3].forEach(function(item) {
  console.log(item);
// 1
// 2
// 3
});

// Shorthand:
sayHello = name => console.log('Hello', name);
sayHello("Chetan"); //Hello Chetan

setTimeout(() => console.log('Loaded'), 2000); //Loaded

[1,2,3].forEach(item => console.log(item));
// 1
// 2
// 3
Comment

arrow function

textBox.addEventListener('keydown', (event) => {
  console.log(`You pressed "${event.key}".`);
});
Comment

arrow function

// Traditional Function
function (a){
  return a + 100;
}

// Arrow Function Break Down

// 1. Remove the word "function" and place arrow between the argument and opening body bracket
(a) => {
  return a + 100;
}

// 2. Remove the body brackets and word "return" -- the return is implied.
(a) => a + 100;

// 3. Remove the argument parentheses
a => a + 100;
Comment

arrow function

// Arrow function with two arguments const sum = (firstParam, secondParam) => {   return firstParam + secondParam; }; console.log(sum(2,5)); // Prints: 7  // Arrow function with no arguments const printHello = () => {   console.log('hello'); }; printHello(); // Prints: hello // Arrow functions with a single argument const checkWeight = weight => {   console.log(`Baggage weight : ${weight} kilograms.`); }; checkWeight(25); // Prints: Baggage weight : 25 kilograms.  // Concise arrow functionsconst multiply = (a, b) => a * b; console.log(multiply(2, 30)); // Prints: 60 
Comment

Arrow functions syntax

const introduction = () => {
    console.log("Hello, my name is Jessica.");
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: js add event listener 
Javascript :: react native setTimeOut error 
Javascript :: javascript array slice() example 
Javascript :: add new html from javascript 
Javascript :: javascript link detector 
Javascript :: path object d3.js 
Javascript :: mock javascript function 
Javascript :: cypress check if an element is visible 
Javascript :: add select option jquery 
Javascript :: button clicker code 
Javascript :: sessionstorage in javascript 
Javascript :: javascript closures 
Javascript :: autocomplete html in react 
Javascript :: multiple images on cloudinary 
Javascript :: show password eye icon angular 9 
Javascript :: javascript greater than or equal to 
Javascript :: readline nodejs 
Javascript :: sequelize compare dates in two columns 
Javascript :: JS how to access a class propert 
Javascript :: react infinte scroll 
Javascript :: jqvmap 
Javascript :: split function in javascript 
Javascript :: copy to clipboard jquery 
Javascript :: what is process.env.NODE_ENV 
Javascript :: remove element json javascript 
Javascript :: nextjs markdown 
Javascript :: remove second last element from array javascript 
Javascript :: req.header express.js 
Javascript :: project to do with javascript 
Javascript :: joi.validate 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =