A JavaScript object groups related values under named properties. Use an object literal for a one-off record; use a constructor function or a class when you want to create multiple similar objects. In both constructor patterns, new creates an instance, and a prototype lets instances share methods.
What is a JavaScript object?
An object is a collection of properties. Each property pairs a key with a value, and a value can be data or a function. A function stored on an object is commonly called a method. See MDN’s guide to working with objects.
const person = {
name: "Mina",
introduce() {
return `Hi, I'm ${this.name}.`;
},
};
console.log(person.name); // "Mina"
console.log(person.introduce()); // "Hi, I'm Mina."
The braces create an object literal. Use dot notation, as in person.name, to read a property, and call a method with parentheses. Here, this.name refers to the name property on the object receiving the method call.
When should you use a constructor?
An object literal is straightforward when you need one object. If you need several objects with the same kinds of properties and behavior, a constructor function or class gives you a reusable way to initialize them. Each created object is an instance.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Constructor function
A constructor function is an ordinary function used with new. By convention, its name starts with a capital letter. Assigning values to this inside it creates properties on the new instance.
function Person(name) {
this.name = name;
}
const mina = new Person("Mina");
const dev = new Person("Dev");
console.log(mina.name); // "Mina"
console.log(dev.name); // "Dev"
When new Person("Mina") runs, JavaScript creates an object, calls Person with that object as this, and returns the new object. The function’s job here is to give each instance its own name.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Class and its constructor method
A class provides another syntax for defining instances. Its constructor() method runs when you create an instance with new and initializes that instance’s properties.
class Person {
constructor(name) {
this.name = name;
}
}
const mina = new Person("Mina");
console.log(mina.name); // "Mina"
The class form and the function-constructor pattern both initialize instances, but they use different syntax. MDN describes the class constructor() as the special method for creating and initializing a class instance; see MDN’s constructor reference.
Recommended Free Tools
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
How does a prototype make methods available?
Each instance has a prototype link. When JavaScript cannot find a property directly on the instance, it checks the instance’s prototype and continues along the prototype chain. A method placed on a constructor’s prototype can therefore be shared by instances instead of being created separately for each one.
function Person(name) {
this.name = name; // own property: each instance has its own value
}
Person.prototype.introduce = function () {
return `Hi, I'm ${this.name}.`;
};
const mina = new Person("Mina");
const dev = new Person("Dev");
console.log(mina.introduce()); // "Hi, I'm Mina."
console.log(dev.introduce()); // "Hi, I'm Dev."
console.log(Object.hasOwn(mina, "name")); // true
console.log(Object.hasOwn(mina, "introduce")); // false
name is an own property because the constructor assigns it to this. introduce is found through the prototype link, so both instances can use the same method. Methods defined in a class body are also placed on the class’s prototype:
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
class Person {
constructor(name) {
this.name = name;
}
introduce() {
return `Hi, I'm ${this.name}.`;
}
}
How do the object-creation options compare?
| Approach | Good fit | Basic syntax | Where shared behavior goes | Requires a constructor definition? |
|---|---|---|---|---|
| Object literal | One-off object | const item = { name: "Mina" }; |
Methods can be properties directly on that object | No |
| Constructor function | Repeated instances using the function-plus-new pattern |
function Person(name) { this.name = name; } |
Person.prototype |
Yes |
| Class | Repeated instances using class syntax | class Person { constructor(name) { this.name = name; } } |
The class prototype; methods go in the class body | Yes, a class definition |
Object.create() |
An object with a deliberately chosen prototype | const person = Object.create(proto); |
The prototype object passed as proto |
No |
Object.create(proto) is an alternative when you want to specify an object’s prototype directly; it does not require a constructor function. MDN covers it alongside object literals and constructor patterns in its object guide.
What does an object’s constructor property mean?
Do not confuse the constructor() method in a class with an object’s constructor property. The class method initializes an instance. The property named constructor is typically inherited from the object’s prototype and often refers to the function that created that prototype.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
That property is not a reliable way to verify an object’s type. It can change if a constructor’s prototype is replaced, and objects created with a null prototype do not inherit the usual Object.prototype properties. MDN documents the inherited property and how prototype reassignment affects it in its Object.prototype.constructor reference. Microsoft Learn notes that most objects inherit from Object.prototype, with null-prototype objects as an exception; see its JavaScript Object reference.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

