Objects (The Root)
Master this topic with zero to advance depth.
Expert Answer & Key Takeaways
Mastering Objects (The Root) is essential for high-fidelity technical architecture and senior engineering roles in 2026.
JavaScript Objects
In JavaScript, objects are king. If you understand objects, you understand JavaScript. Almost "everything" in JavaScript is an object (except for primitives).
1. Object Definition
You define (and create) a JavaScript object with an object literal:
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};Spaces and line breaks are not important. An object definition can span multiple lines.
2. Creating an Object with 'new'
The following example also creates a new JavaScript object with four properties:
const person = new Object();
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;
person.eyeColor = "blue";[!IMPORTANT] For readability, simplicity and execution speed, use the object literal method ({}) instead of thenew Object()constructor.
3. JavaScript Objects are Containers
Objects are containers for named values called properties. They can also contain functions, which are called methods.
4. Accessing Object Properties
You can access object properties in two ways:
Dot notation:
objectName.propertyName;
person.firstName; // Returns "John"Bracket notation:
objectName["propertyName"];
person["firstName"]; // Returns "John"Bracket notation is especially useful when the property name is stored in a variable or contains special characters (like spaces).
Top Interview Questions
?Interview Question
Q:What is the difference between an Object and a Primitive in JS?
A:
Primitives (like numbers, strings) are single values that are immutable and have no properties. Objects are collections of related data and/or functionality (methods) and are mutable.
?Interview Question
Q:When should you use bracket notation over dot notation?
A:
Use bracket notation when the property name is dynamic (stored in a variable) or when it contains characters that aren't valid in dot notation (like spaces or hyphens).
?Interview Question
Q:Is 'const' used with objects making them immutable?
A:
No. 'const' only prevents the variable from being reassigned to a different object. You can still modify the properties inside the object (this is called mutation).
Course4All Engineering Team
Verified ExpertSenior Full-Stack Engineers & V8 Experts
Our JavaScript and engine-level content is developed by a collective of senior engineers focused on high-performance web architecture and 2026 standards.
Pattern: 2026 Ready
Updated: Weekly
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.