Recently I've been learning node.js, and I've found two code fragments like this:
Fragment 1:
const fs = require('fs')
fs.readFile("content.txt", "utf8", (err, msg) => {
console.log(msg);
})
Fragment 2:
const fs = require('fs')
fs.readFile("content.txt", (err, msg) => {
console.log(msg);
})
They have only one difference that Fragment 1 passed 'utf8' as the second parameter while Fragment 2 skips to pass it. And although they have different results, both of them can function normally without a syntax error.
So I wonder how a javascript method is able to skip to pass the parameter? And how can I define a method/function like this?