Function name

  • Gets the name of a value.

    If the value is a function, its name is returned. If the value is a symbol, its key is returned. If the value is a string, it is returned as is. Otherwise, null is returned.

    Since

    10.2.0

    Returns

    The name of the value.

    Example

    name(class Foo{})
    // => "Foo"

    name(function bar(){})
    // => "bar"

    name(Symbol.for("abc"))
    // => "abc"

    name("foo")
    // => "foo"

    name(1)
    // => null

    Parameters

    • value: unknown

      Value to check.

    Returns null | string

Generated using TypeDoc