sindresorhus/is-identifier

Check if a string is a valid JavaScript identifier

JavaScript

27

6 commits

updated Jul 5, 2026

See the code

README

is-identifier

Check if a string is a valid JavaScript identifier

Install

npm install is-identifier

Usage

import isIdentifier from 'is-identifier';

isIdentifier('foo');
//=> true

isIdentifier('1kg');
//=> false

isIdentifier('await'); // Reserved identifier
//=> false

[!NOTE] Although globalThis, Infinity, NaN, and undefined are properties of the global object and not identifiers, they are treated as reserved here because they should generally not be used as identifiers.

API

isIdentifier(value, options?)

Returns a boolean for whether the given value is a valid JavaScript identifier.

options

Type: object

checkReserved

Type: boolean
Default: true

Reject reserved words and global properties like if, await, and undefined.

These are valid identifier syntax but should not be used as variable names, so they are rejected by default. Disable this when you only care about the syntax, such as for property keys ({if: 1}) or dot notation (foo.for), where they are allowed.

import isIdentifier from 'is-identifier';

isIdentifier('for', {checkReserved: false});
//=> true

sindresorhus/is-identifier

Check if a string is a valid JavaScript identifier

JavaScript

27

6 commits

updated Jul 5, 2026

See the code

README

is-identifier

Check if a string is a valid JavaScript identifier

Install

npm install is-identifier

Usage

import isIdentifier from 'is-identifier';

isIdentifier('foo');
//=> true

isIdentifier('1kg');
//=> false

isIdentifier('await'); // Reserved identifier
//=> false

[!NOTE] Although globalThis, Infinity, NaN, and undefined are properties of the global object and not identifiers, they are treated as reserved here because they should generally not be used as identifiers.

API

isIdentifier(value, options?)

Returns a boolean for whether the given value is a valid JavaScript identifier.

options

Type: object

checkReserved

Type: boolean
Default: true

Reject reserved words and global properties like if, await, and undefined.

These are valid identifier syntax but should not be used as variable names, so they are rejected by default. Disable this when you only care about the syntax, such as for property keys ({if: 1}) or dot notation (foo.for), where they are allowed.

import isIdentifier from 'is-identifier';

isIdentifier('for', {checkReserved: false});
//=> true

Project health

Latest release

1.1.0 · Jul 5, 2026

Releases this year

1

Significant stargazers

Christian Owusu

8 followers · starred May 2024