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

How to reverse an Array?

Reversing an array in JS is really simple with the standard array method. Like below

10 mẹo sử dụng array và object trong javascript

10 mẹo sử dụng array và object 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.

flatMap()

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

Detect when your site is visible to users

Detect when your site is visible to users