Skip to content

Commit

Permalink
[Term Entry] JavaScript Objects: .create()
Browse files Browse the repository at this point in the history
* added Postgresql positional-parameters

* added Object.create() file in thejs folder

* Update content/javascript/concepts/objects/terms/create/create.md

Co-authored-by: mamtawardhani <53176352+mamtawardhani@users.noreply.github.com>

* Update content/javascript/concepts/objects/terms/create/create.md

Co-authored-by: mamtawardhani <53176352+mamtawardhani@users.noreply.github.com>

* made corrections to  Object.create() file in thejs folder

* Update content/javascript/concepts/objects/terms/create/create.md

* Update content/javascript/concepts/objects/terms/create/create.md

* Delete content/postgresql/concepts/positional-parameters/positional-parameters.md

Deleted the positional-parameters file

* Update create.md

* Update create.md

* Minor changes

---------
  • Loading branch information
amarachi-nwokocha committed May 14, 2024
1 parent 091a053 commit 29d6441
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions content/javascript/concepts/objects/terms/create/create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
Title: '.create()'
Description: 'Creates a new object with the specified prototype object and properties.'
Subjects:
- 'Code Foundations'
- 'Computer Science'
Tags:
- 'Algorithms'
- 'Inheritance'
- 'Methods'
- 'Objects'
CatalogContent:
- 'introduction-to-javascript'
- 'paths/front-end-engineer-career-path'
---

In JavaScript, the **`.create()`** [method](https://www.codecademy.com/resources/docs/javascript/methods) creates a new object with the specified prototype object and optional additional properties. It essentially allows developers to create an object that inherits properties from another object.

## Syntax

```pseudo
Object.create(prototype[, propertiesObject])
```

- `prototype`: The object that serves as the blueprint for the newly created object.
- `propertiesObject` (Optional): The object whose properties are added to the newly created object.

## Example

The following example explains the use of the `.create()` method:

```js
// Creating an object to serve as the prototype
var prototypeObject = {
greet: function () {
return 'Hello!';
},
};

// Creating a new object with 'prototypeObject' as its prototype
var newObj = Object.create(prototypeObject);

// 'newObj' inherits the 'greet' function from 'prototypeObject'
console.log(newObj.greet());
```

The above code produces the following output:

```shell
Hello!
```

In the above example, an object named `prototypeObject` is created with a `greet()` method. Subsequently, `.create()` generates a new object `newObj`, inheriting the `greet()` method from `prototypeObject`. The invocation `newObj.greet()` then outputs `Hello!` to the console.

0 comments on commit 29d6441

Please sign in to comment.