Skip to content

Files

Latest commit

 

History

History
27 lines (19 loc) · 656 Bytes

func-names.md

File metadata and controls

27 lines (19 loc) · 656 Bytes

Pattern: Anonymous function expression

Issue: -

Description

Anonymous functions show up as '' in stack traces, making it difficult to debug errors. Named function expressions provide better stack traces by including the function name, making it easier to identify where an error occurred.

Examples

Example of incorrect code:

Foo.prototype.bar = function() {};

const handler = function() {
  throw new Error('Something went wrong');
};

Example of correct code:

Foo.prototype.bar = function bar() {};

const handler = function errorHandler() {
  throw new Error('Something went wrong');
};