# Basics

To create a copy of an immutable object in JavaScript, you can use the `Object.assign()` method or the spread operator (`...`). These methods allow you to create a new object with the properties of the original object and then modify the new object as needed.

For example:

```javascript
const person = {
  name: 'John',
  age: 30
};

// Using Object.assign()
const personCopy1 = Object.assign({}, person, { name: 'Jane' });

// Using the spread operator
const personCopy2 = { ...person, name: 'Jane' };

console.log(personCopy1); // { name: 'Jane', age: 30 }
console.log(personCopy2); // { name: 'Jane', age: 30 }
```

To update an immutable object, you can create a copy of the object with the desired changes, and then use `Object.freeze()` or `Object.seal()` to prevent the object from being modified further.

For example:

```javascript
const person = {
  name: 'John',
  age: 30
};

const updatedPerson = Object.freeze({ ...person, age: 31 });

console.log(updatedPerson); // { name: 'John', age: 31 }
```

To delete a property from an immutable object, you can create a copy of the object with the desired property removed.

For example:

```javascript
const person = {
  name: 'John',
  age: 30,
  address: '123 Main St'
};

const updatedPerson = Object.freeze({
  ...person,
  address: undefined
});

console.log(updatedPerson); // { name: 'John', age: 30 }
```

It's also possible to use a library like Immutable.js, which provides methods for creating, updating, and deleting properties on immutable objects.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://demirels-organization.gitbook.io/javascript-tutorial/immutable-object-operations/basics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
