The JavaScript Symbol.hasInstance property finds out that a constructor object recognizes an object as its instance or not.
Syntax:
[Symbol.hasInstance] (object)
Parameters:
object: It represents the specific object to be checked as a symbol instance.
Returns:
It returns true if the object is an instance of a symbol, otherwise returns false.
Example 1:
<!DOCTYPE html> <html> <body> <script> var alpha = ['a','b']; document.write( Array[ Symbol.hasInstance ](alpha) ); </script> </body> </html>
Example 2:
<!DOCTYPE html> <html> <body> <script> class ArrayTest { static [Symbol.hasInstance](instance) { return Array.isArray(instance); } } document.write([] instanceof ArrayTest); </script> </body> </html>