Callback in javascript

callback,tipjs

Callback in javascript

const fs = require('fs')
fs.readFile('/etc/passwd', (err, data) => {
  if (err) {
    console.error(err)
    return
  }
  console.log(data.toString())
})

Sử dụng callback rất hạn chế ví dụ :

fs.readFile(fileA, function (err, data) {
  fs.readFile(fileB, function (err, data) {
    // ...
  })
}

Có thể bạn đã miss một số snippets code

Merge Array

How to combine two sorted arrays into one? We can do this easily with the spread operator.

flatMap()

Use flatMap() creates a new array with sub-array elements flattened by specified depth.

Await in a for loop

How to Await in a for loop

JavaScript: async/await with forEach

JavaScript: async/await with forEach()

Detect when your site is visible to users

Detect when your site is visible to users