# Function Name

> Determine a function's name.


<section class="usage">

## Usage

``` javascript
var functionName = require( '@stdlib/utils/function-name' );
```

#### functionName( fcn )

Returns the name of a `function`.

``` javascript
var name = functionName( Math.sqrt )
// returns 'sqrt'
```

If provided an __anonymous__ `function`, the function returns an empty `string` or the string `"anonymous"`.

``` javascript
var name = functionName( function(){} );
// returns '' || 'anonymous'
```

If provided a value which is not a `function`, the function __throws__ a `TypeError`.

``` javascript
try {
    // throws...
    var name = functionName( 'beep' );
} catch ( err ) {
    console.error( err );
}
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

* For more information regarding the naming of anonymous functions, see

  - [Function Names in ES6][2ality]
  - Webkit bug [7726][webkit-bug-7726]
  - [MDN][mdn]

</section>

<!-- /.notes -->


<section class="examples">

## Examples

``` javascript
var functionName = require( '@stdlib/utils/function-name' );

var bool = functionName( Math.sqrt );
// returns 'sqrt'

bool = functionName( Float64Array );
// returns 'Float64Array'

bool = functionName( Buffer );
// returns 'Buffer'

bool = functionName( Date );
// returns 'Date'

bool = functionName( String );
// returns 'String'

bool = functionName( Boolean );
// returns 'Boolean'

bool = functionName( Function );
// returns 'Function'

bool = functionName( Number );
// returns 'Number'

bool = functionName( function foo() {} );
// returns 'foo'

bool = functionName( function () {} );
// returns '' || 'anonymous'
```

</section>

<!-- /.examples -->


<section class="links">

[2ality]: http://www.2ality.com/2015/09/function-names-es6.html
[webkit-bug-7726]: https://bugs.webkit.org/show_bug.cgi?id=7726
[mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name

</section>

<!-- /.links -->
