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.

Kiểm tra định dạng email bằng Javascript

Kiểm tra định dạng email bằng Javascript

serialize Form

Sử dụng formdata constructor để convert form, FormData, array.from(). Kết hợp window.encodeURIComponent() để encode từng value trong form.

group by property javascript use reduce

group by property javascript use reduce

Spread Operator for Objects

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