JavaScript Symbol.hasInstance Property - JavaScript Tutorial

JavaScript Symbol.hasInstance Property

BLUF: This tutorial on JavaScript Symbol.hasInstance Property provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Symbol.hasInstance Property

Understanding JavaScript Symbol.hasInstance Property is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The JavaScript Symbol.hasInstance is utilized to ascertain whether a constructor object identifies a particular object as an instance of itself.

Syntax

Example

[Symbol.hasInstance] (obj)

Parameters

An object as one of the constructor.

Return value

Return true if the specified value exists within the object's chain; otherwise, return false.

Browser Support

Chrome 5.1
Safari Yes
Firefox 50
Opera Yes

Example 1

Example

<script>

//JavaScript to illustrate Symbol.hasInstance

var pyVisualizer = [12,45];

document.write( Array[ Symbol.hasInstance ](pyVisualizer) );

//expected output:true

</script>

Output:

Example 2

Example

<script>

//JavaScript to illustrate Symbol.hasInstance

//Using user define function

function pyVisualizer()

{}

var Script = new PyVisualizer 

document.write( pyVisualizer[ Symbol.hasInstance ](Script) );

//expected output:true

</script>

Output:

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience