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

try/catch es10

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

Spread Operator for Objects

Using the spread operator during an Object declaration will assign the properties of the referenced Object to the new Object.

Await in a for loop

How to Await in a for loop

promise in javascript

promise in javascript

Copy a string to the clipboard

Copy a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).