Search code examples
javascriptnode.jsecmascript-6symbols

Check if value is a Symbol in JavaScript


How can I check if a value is Symbol in JS?

I do not see a Symbol.isSymbol(x) method. My test of (x instanceof Symbol) does not seem to work either.


Solution

  • Check it with typeof:

    typeof x === 'symbol'