<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hoài Nhớ</title>
    <description>The latest articles on DEV Community by Hoài Nhớ (@hoainho).</description>
    <link>https://dev.to/hoainho</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1921843%2Fc65edb8c-9e64-4f00-8b63-d9c479ea7f99.jpg</url>
      <title>DEV Community: Hoài Nhớ</title>
      <link>https://dev.to/hoainho</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hoainho"/>
    <language>en</language>
    <item>
      <title>🔓Unlocking JavaScript Power: Master Advanced Object Features for Efficient Code</title>
      <dc:creator>Hoài Nhớ</dc:creator>
      <pubDate>Fri, 27 Sep 2024 01:45:21 +0000</pubDate>
      <link>https://dev.to/hoainho/unlocking-javascript-power-master-advanced-object-features-for-efficient-code-3945</link>
      <guid>https://dev.to/hoainho/unlocking-javascript-power-master-advanced-object-features-for-efficient-code-3945</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This document explores advanced features of JavaScript objects, delving into their capabilities and functionalities that enhance the way developers can manipulate and interact with data structures. By understanding these advanced features, developers can write more efficient, maintainable, and powerful code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37zp19jel0t359olvl2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37zp19jel0t359olvl2t.png" alt="Advanced Object Features in Javascript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Object Creation
&lt;/h3&gt;

&lt;p&gt;JavaScript provides various ways to create objects, including:&lt;/p&gt;

&lt;h3&gt;
  
  
  1.1 Object Literal
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person = {
    name: 'John',
    age: 30,
    greet() {
        console.log(`Hello, my name is ${this.name}`);
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1.2 Constructor Function
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person(name, age) {
    this.name = name;
    this.age = age;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const john = new Person('John', 30);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1.3 ES6 Classes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    greet() {
        console.log(`Hello, my name is ${this.name}`);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const john = new Person('John', 30);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Object Prototypes
&lt;/h3&gt;

&lt;p&gt;JavaScript uses prototypes to enable inheritance. Every object has a prototype, which is itself an object.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.1 Prototype Chain
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Animal(name) {
    this.name = name;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Animal.prototype.speak = function() {
    console.log(`${this.name} makes a noise.`);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dog = new Animal('Dog');
dog.speak(); // Dog makes a noise.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Object Destructuring
&lt;/h3&gt;

&lt;p&gt;Destructuring allows unpacking values from arrays or properties from objects into distinct variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = {
    id: 1,
    name: 'Alice',
    age: 25
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { name, age } = user;
console.log(name); // Alice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Object Spread and Rest
&lt;/h3&gt;

&lt;p&gt;The spread operator (&lt;code&gt;...&lt;/code&gt;) allows for easy copying and merging of objects.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.1 Spread Operator
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgd0qtakg7g00qah1jbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgd0qtakg7g00qah1jbn.png" alt="What's spread Operator look like?"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj1 = { a: 1, b: 2 };
const obj2 = { ...obj1, c: 3 };
console.log(obj2); // { a: 1, b: 2, c: 3 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4.2 Rest Parameters
&lt;/h3&gt;

&lt;p&gt;Rest parameters allow you to represent an indefinite number of arguments as an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sum(...numbers) {
    return numbers.reduce((acc, num) =&amp;gt; acc + num, 0);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(sum(1, 2, 3, 4)); // 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Object Methods
&lt;/h3&gt;

&lt;p&gt;JavaScript provides several built-in methods for object manipulation.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.1 Object.keys()
&lt;/h3&gt;

&lt;p&gt;Returns an array of a given object’s own enumerable property names.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { a: 1, b: 2 };
console.log(Object.keys(obj)); // ['a', 'b']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.2 Object.values()
&lt;/h3&gt;

&lt;p&gt;Returns an array of a given object’s own enumerable property values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Object.values(obj)); // [1, 2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.3 Object.entries()
&lt;/h3&gt;

&lt;p&gt;Returns an array of a given object’s own enumerable string-keyed property [key, value] pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Object.entries(obj)); // [['a', 1], ['b', 2]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Object.freeze(), Object.seal(), and Object.preventExtensions()
&lt;/h3&gt;

&lt;p&gt;These methods control the mutability of objects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F572y21kal56votjtxnxa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F572y21kal56votjtxnxa.png" alt="How to freeze for an Object to avoid modification"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6.1 Object.freeze()
&lt;/h3&gt;

&lt;p&gt;Prevents new properties from being added to an object and marks all existing properties as read-only.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { a: 1 };
Object.freeze(obj);
obj.a = 2; // No effect
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6.2 Object.seal()
&lt;/h3&gt;

&lt;p&gt;Prevents new properties from being added to an object but allows existing properties to be modified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { a: 1 };
Object.seal(obj);
obj.a = 2; // Allowed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6.3 Object.preventExtensions()
&lt;/h3&gt;

&lt;p&gt;Prevents new properties from being added to an object but allows existing properties to be modified or deleted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p6r5c02ji4p8fvty6rr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p6r5c02ji4p8fvty6rr.png" alt="Attribute hidden of secret"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { a: 1 };
Object.preventExtensions(obj);
obj.b = 2; // Not allowed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Understanding advanced JavaScript object features is essential for modern web development. These features not only enhance code readability and maintainability but also empower developers to create more dynamic and efficient applications. By leveraging these capabilities, developers can take full advantage of JavaScript’s powerful object-oriented programming paradigm.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
