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

kiểm tra email trong javascript

kiểm tra email trong javascript

encode/decode base64 with JS

Encoding to base64 is done with the btoa command

Sử dụng reduce và concat làm phẳng một array

Array.reduce() và Array.concat() có thể giúp chúng ta làm phẳng một Array như:

group by property javascript use reduce

group by property javascript use reduce

try/catch es10

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