I was reading the logging library source code when I found syntax I had never seen before, and which didn't seem to have any effect when evaluated via an interpreter:
const createLogger = (title,
{
debugFunction = createDebug(title),
logFunction = console.log
} = {}) => { /* ... */ }
- What is this syntax called?
- What effect does this syntax have?
- Can the object be referenced from within the function body?
Output of ts-node
attempt to recreate:
> const testFn2 = (arg1, {dFn = console.debug, lFn = console.log} = {}) => { console.log(arguments) }
undefined
> testFn2(1)
{ '0': 1 }
undefined
> testFn2(1, 2)
{ '0': 1, '1': 2 }
undefined
> testFn2(1, {})
{ '0': 1, '1': {} }
undefined