Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

name arrow function

//Long version  
function add(a, b) {  
    return a + b;   
}

// Shorthand  
const add = (a, b) => a + b;   
Comment

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

Arrow Function Example

let nums = [3, 5, 7]
let squares = nums.map(function (n) {
  return n * n
})
console.log(squares)
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

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

Arrow Function Example

let nums = [3, 5, 7]
let squares = nums.map((n) => {
  return n * n
})
console.log(squares)
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

PREVIOUS NEXT
Code Example
Javascript :: vuex do not mutate vuex store state outside mutation handlers. nuxt 
Javascript :: forever.js 
Javascript :: how to check for enter keyPress in react native 
Javascript :: compare between two arrays javascript 
Javascript :: md 5 npm 
Javascript :: how to get the last two characters of a string in javascript 
Javascript :: javascript one line if else 
Javascript :: tailwind container class size 
Javascript :: gltfjsx 
Javascript :: filter an array 
Javascript :: jquery clear text in div 
Javascript :: mangoose connection 
Javascript :: what is linter javascript 
Javascript :: detect if overflow javascript 
Javascript :: check env 
Javascript :: angularjs format number thousands separator 
Javascript :: full month name using moment 
Javascript :: react strict mode 
Javascript :: new date getday js 
Javascript :: event.propagation not working 
Javascript :: js fetch status of 500 
Javascript :: how to concatenate a string in javascript 
Javascript :: carbon to moment js conversion 
Javascript :: how sum all array element with for 
Javascript :: react native map 
Javascript :: is javascript faster than python 
Javascript :: what is asynchronous 
Javascript :: simple node rest 
Javascript :: what is jquery used for 
Javascript :: Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec. 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =