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

Callback in javascript

Callback in javascript

Lấy ngày hiện tại trong javascript

Lấy ngày hiện tại trong javascript

try/catch es10

An update for developer convience allows the use of try/catch without an explicit e Error reference in the catch call.

Đếm có bao nhiêu items giống nhau trong một array

reduce javascript. Đếm có bao nhiêu items giống nhau trong một array

flatMap()

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