Search code examples
javascriptnode.jsexpressecmascript-6ecmascript-5

ExpressJs : Safe To Use Reserved Word DELETE as method name?


Delete is one of the reserved words in JavaScript however ExpressJS uses it as a method name. Their Basic Routing documentation shows:

app.METHOD(PATH, HANDLER)

Where:

app is an instance of express. METHOD is an HTTP request method, in lowercase. PATH is a path on the server. HANDLER is the function executed when the route is matched.

And what I would like to do is export a delete method for my router, e.g. router.delete('/api/v1/:id', handler.delete); however I don't want to further violate the language. Would it be bad practice to export a module.exports.delete = deleteHandler?


Solution

  • delete is only a keyword in specific contexts, it can sometimes be used as an identifier like for can.

    assigning for as a property of an object foo

    If the word delete makes sense to you, and it is consistent with other things you've done, then there isn't anything wrong with it.