Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge
  • All
  • C#
  • MVC
  • Web API
  • Azure
  • IIS
  • JavaScript
  • Angular
  • Node.js
  • Java
  • Python
  • SQL Server
  • SEO
  • Entrepreneur
  • Productivity

How to check the type of an instance in JavaScript?

The instanceof operator determines whether a left-hand side object is created from a specified constructor function in its prototype chain.

object instanceof constructor

  • object = variable name
  • constructor = constructor function name used with the "new" keyword
Example: instanceof
function func1(){  };
function func2(){  };

var f1 = new func1();

f1 instanceof func1; //returns true

f1 instanceof func1; //returns false

f1 instanceof Object; //returns true
Try it

Please note that the instanceof operator returns "true" if a variable is initialized with the "new" keyword.

Example: instanceof
var stringObj = new String();
var str = "this is str";

stringObj instanceof String; //returns true
str instanceof String; //returns false
Try it

Visit MDN for more information.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.