 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Call a JavaScript class object with variable?
Let’s say the following is our variable −
var message = 'This is the Class Demo';
Following is our object,
var object = new FirstClass(message)
The class FirstClass −
class FirstClass{
   constructor( message){
      this.message = message;
   }
}
We will use eval() to call a JavaScript class object with variable. Following is the code −
Example
class FirstClass{
   constructor( message){
      this.message = message;
   }
}
var message = 'This is the Class Demo';
var object = new FirstClass(message)
console.log(eval(object).message);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo121.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo121.js This is the Class Demo
Advertisements
                    