- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it possible to create a new data type in JavaScript?
Yes, you can use the concept of Class. If you want to check the actual data type then you can use instanceof.
The instanceof tells about the data type. Here is the sample JavaScript code which will give a brief description about how to create a new data type and how to check the data type. Here, I will give the custom implementation to check the data type.
Example
Following is the code −
//creating the class class Game { constructor(gameName) { this.gameName = gameName; } } //creating an object const ticTacToe = new Game("TicTacToe"); // checking the data type. function dataTypeBelongsTo(object) { if (object instanceof Game) return "Game"; return typeof object; } console.log("The ticTacToe is the object of Game class=" + (ticTacToe instanceof Game)); console.log("The data Type of ticTacToe is =" + dataTypeBelongsTo(ticTacToe)); console.log("The data Type Candy Cash is =" + dataTypeBelongsTo("Cady Cash"));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo288.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo288.js The ticTacToe is the object of Game class=true The data Type of ticTacToe is =Game The data Type Candy Cash is =string
- Related Articles
- Is it possible to write data to file using only JavaScript?
- Is it possible to instantiate Type-parameter in Java?
- Is it possible to synchronize the string type in Java?
- Is it possible to create static constructor in java?
- Is it possible to create a class without a name in Java?
- Why is it important to create a Data Backup?
- Is it possible to change the HTML content in JavaScript?
- Add a new value to a column of data type enum in MySQL?
- Is it possible to write to MongoDB console in JavaScript execution?
- Is it possible to create a custom exception in java without extending Exception class?
- Check if it is possible to create a polygon with a given angle in Python
- Is it possible to select text boxes with JavaScript?
- Is it possible to enforce data checking in MySQL using Regular Expression?
- Is it possible to validate the size and type of input=file in HTML5?
- Is it possible to display substring from object entries in JavaScript?

Advertisements