isSymbol
Using
This function determines whether the given value is a symbol primitive.
- Returns
true
only if the value is of typesymbol
(e.g.,Symbol()
,Symbol.iterator
,Symbol.for()
). - Returns
false
for all other types, including boxed symbols (e.g.,Object(Symbol())
,new Symbol()
).
Arguments
Argument | Type | Description | Example |
---|---|---|---|
value | unknown | Can be any type | "text" 2 undefined |
Returns
boolean
— true
if value is a symbol primitive, false
otherwise
Examples
isSymbol(Symbol());
// true
isSymbol(Symbol.iterator);
// true
isSymbol(Symbol.for('key'));
// true
isSymbol('symbol');
// false
isSymbol(Object(Symbol()));
// false
isSymbol(new Symbol());
// false
isSymbol(() => Symbol());
// false