web reptile explanation -URLLIB Library Ruddy -Basic use -timeout settings -automatic simulation HTTP request

2023-01-23   ES  

recently used the arrow function in the project frequently, in the process of usingreturnKeyword usage is more confused. The following methods are recorded:

  • If the code block of the arrow function is more than one sentence, you need to use large brackets to include them and usereturnKeyword Return


const foo = (a, b) => {
foo(1, 2) // undefined

const foo1 = (a, b) => {
   return a+b;
foo1(1, 2) // 3

All the parts that are included in brackets If you want to get the return value, you must use itreturnKeywords return, otherwise returnundefined

  • If the arrow function only has a line of sentences, it can omit large brackets and omitreturnKeywords.
const foo = (a, b) => a+b // equivalent to const foo = (a, b) => {return a+b}
foo(1, 2) // 3

Herefoo = (a, b) => a+bequivalent tofoo = (a, b) => { return a+b }

The above usage can be used to simplify the callback function, see the following example:

// Normal function writing
[1,2,3].map(function (x) {
  return x * x;

// Arrow function writing
[1,2,3].map(x => x * x);

can be seen, we used the arrow function to omit the function{}returnKeywords make the function more concise.

Below is my public account QR code picture, welcome to follow.


Related Posts

Fifth week after class practice: Project 4 -Organize multiple classes with multiple files

java —— generic limited (occupying symbol)

python3 network crawler (1) -The novel crawling (take the website novel as an example) isana) Isana

Android Studio Common plug -in and dependent ABNER

web reptile explanation -URLLIB Library Ruddy -Basic use -timeout settings -automatic simulation HTTP request

Random Posts

linux file attributes of software and hard connection knowledge in depth explanation

GSON practical journey


Use ImageTransport API in ROS to collect your data into Rosbag

Ubuntu Install Lightweight Desktop