--- id: javascript-objects title: "JavaScript Objects" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["JS objects", "object literal", "object definitions", "new Object", "key value pairs", "objects are mutable", "primitives"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.86 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "objects", "object-literal", "primitives"] raw_sources: ["https://www.w3schools.com/js/js_objects.asp", "https://www.w3schools.com/js/js_object_definition.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Objects]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Objects are variables that can store both values and functions, and in JavaScript almost everything except primitives is an object β€” addressed by reference, not by value. [S1][S2] ## 🧠 핡심 κ°œλ… (Core concepts) - **Objects store values and functions** β€” they are one of the most important concepts in JavaScript. [S1] - **Key:value pairs** β€” an object literal is a list of property `key:value` pairs inside curly braces `{ }`. [S2] - **Many ways to define** β€” object literal, the `new` keyword, an object constructor, `Object.assign()`, `Object.create()`, and `Object.fromEntries()`. [S2] - **Objects are king** β€” in JavaScript almost everything is an object; all JavaScript values except primitives are objects. [S2] - **Objects are mutable and passed by reference** β€” they are addressed by reference, not by value, so a "copy" actually shares the same memory. [S2] - **Primitives are immutable** β€” the seven primitive types hold a single value that cannot be changed. [S2] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Prefer the object literal** β€” for readability, simplicity, and execution speed, use the object literal over `new Object()`. [S2] - **Reference-aliasing caution** β€” `const x = person;` does not copy; `x` *is* `person`, so changing `x.age` changes `person.age`. [S2] - **Build objects from data** β€” `Object.fromEntries()` constructs an object from iterable key/value pairs; `Object.assign()` merges sources into a target. [S2] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **What JavaScript objects are** Objects are variables that can store both values and functions, and they are one of the most important concepts in JavaScript. The learning path covers object basics, properties (which can be changed, added, and deleted), methods (functions stored as property values), the `this` keyword (which refers to the calling object), display techniques (loops and `JSON.stringify()`), and constructors (for creating multiple objects of the same type). [S1] **Using an Object Literal** An object literal is a list of property `key:value` pairs inside curly braces `{ }`. [S2] ```javascript {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}; ``` ```javascript // Create an Object const person = { firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue" }; ``` Note: there is no need to use `new Object()`. For readability, simplicity, and execution speed, use the object literal method. Objects written as name/value pairs are similar to associative arrays in PHP, dictionaries in Python, hash tables in C, hash maps in Java, and hashes in Ruby and Perl. [S2] **Using the new Keyword** [S2] ```javascript // Create an Object const person = new Object({ firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue" }); ``` The examples above do exactly the same. [S2] **Object.create()** The `Object.create()` method creates an object from an existing object. [S2] ```javascript // Create an Object: const person = { firstName: "John", lastName: "Doe" }; // Create new Object const man = Object.create(person); man.firstName = "Peter"; ``` **Object.fromEntries()** ES2019 added the `fromEntries()` method, which creates an object from iterable key/value pairs. [S2] ```javascript const fruits = [ ["apples", 300], ["pears", 900], ["bananas", 500] ]; const myObj = Object.fromEntries(fruits); ``` `fromEntries()` is an ECMAScript 2019 feature, supported in all modern browsers since January 2020. [S2] | Browser | Version | Release Date | | --- | --- | --- | | Chrome | 66 | Apr 2018 | | Edge | 79 | Jan 2020 | | Firefox | 61 | Jun 2018 | | Safari | 12 | Sep 2018 | | Opera | 50 | May 2018 | **Object.assign()** The `Object.assign()` method copies properties from one or more source objects to a target object. [S2] ```javascript // Create Target Object const person1 = { firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue" }; // Create Source Object const person2 = {firstName: "Anne",lastName: "Smith"}; // Assign Source to Target Object.assign(person1, person2); ``` **In JavaScript, Objects are King** "If you understand objects, you understand JavaScript." In JavaScript, almost everything is an object: objects are objects, maths are objects, functions are objects, dates are objects, arrays are objects, maps are objects, and sets are objects. All JavaScript values, except primitives, are objects. [S2] **JavaScript Primitives** A primitive data type can only store a single primitive value. There are seven primitive types: [S2] | Type | Example Value | | --- | --- | | `string` | "Hello" | | `number` | 3.14 | | `boolean` | true | | `bigint` | 12345678901234n | | `null` | null | | `undefined` | undefined | | `symbol` | symbol | Primitive values are immutable (they are hardcoded and cannot be changed). If `x = 3.14`, you can change the value of `x`, but you cannot change the value of `3.14`. [S2] **JavaScript Objects are Mutable** Objects are mutable: they are addressed by reference, not by value. If `person` is an object, `const x = person;` will not create a copy of `person`. The object `x` is not a copy of `person` β€” `x` *is* `person`; they share the same memory address, and any change to `x` also changes `person`: [S2] ```javascript //Create an Object const person = { firstName:"John", lastName:"Doe", age:50, eyeColor:"blue" } // Try to create a copy const x = person; // This will change age in person: x.age = 10; ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) | Definition method | When to use | Note | | --- | --- | --- | | Object literal `{ }` | Default choice | Best readability, simplicity, execution speed [S2] | | `new Object()` | Equivalent to literal | Does exactly the same; literal preferred [S2] | | `Object.create()` | Create from an existing object | Inherits from the source object [S2] | | `Object.assign()` | Merge sources into a target | Copies properties from source(s) [S2] | | `Object.fromEntries()` | Build from key/value pairs | ES2019 feature [S2] | ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” the `person` object literal, the `new Object()` equivalent, `Object.create()`/`Object.assign()`/`Object.fromEntries()`, and the reference-aliasing demonstration. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Preferred object literal: ```javascript const person = { firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue" }; ``` Reference aliasing (not a copy): ```javascript const x = person; x.age = 10; // also changes person.age ``` Build an object from key/value pairs: ```javascript const myObj = Object.fromEntries(fruits); ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. Version notes: `Object.fromEntries()` is an ECMAScript 2019 feature supported in all modern browsers since January 2020. [S2] ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.86 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery). Note: the js_objects.asp page is an overview/index; code detail is grounded in the linked "Object Definitions" lesson [S2]. ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Object Properties]], [[JavaScript Object Methods]], [[JavaScript Object this]], [[JavaScript Object Display]] - **μ°Έμ‘° λ§₯락:** The foundation for all object-related topics β€” properties, methods, `this`, and display. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Objects β€” https://www.w3schools.com/js/js_objects.asp - [S2] W3Schools β€” JavaScript Object Definitions β€” https://www.w3schools.com/js/js_object_definition.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Objects" page (Astra wiki-curation, P-Reinforce v3.1 format).