JavaScript275 Documents

Inspectable Object Return

Never return an object while creating it. Assign the object to a variable first, then return the variable so the object can be logged or inspected with a breakpoint before it is returned.

Correct

const getItem = title => {
    const item = { title }
    return item
}

Incorrect

const getItem = title => {
    return { title }
}

Fix

Assign the object to a meaningfully named variable immediately before returning that variable.