You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notes/English/29-Object.md
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
-
### What is an object in javascript
1
+
### What is an object ?
2
2
In JavaScript, an object is a collection of key-value pairs, where the keys are strings (or symbols) and the values can be any JavaScript data type, including other objects. Objects in JavaScript are dynamic, meaning that their properties can be added, modified, or removed at runtime. They are also reference types, which means that when you assign an object to a variable, the variable holds a reference to the object in memory rather than a copy of its value.
3
3
4
4
5
-
### What is Object literal syntax in javascript
5
+
### What is Object literal syntax ?
6
6
Object literal syntax in JavaScript is a way to create an object by directly defining its properties and values within curly braces. It is a shorthand notation for creating objects without using the constructor function. For example:
7
7
8
-
```
8
+
```javascript
9
9
constmyObject= {
10
10
name:'John',
11
11
age:30,
@@ -16,7 +16,7 @@ const myObject = {
16
16
This creates an object `myObject` with three properties: `name`, `age`, and `city`, each with a corresponding value. Object literal syntax is a common and convenient way to create objects in JavaScript.
17
17
18
18
19
-
### How to create Object using new keyword in javascript
19
+
### How to create Object using new keyword ?
20
20
To create an object using the `new` keyword in JavaScript, you can define a constructor function and use the `new` keyword to instantiate an object of that type. Here's an example:
21
21
22
22
```
@@ -36,7 +36,7 @@ In this example, we define a constructor function called `Person`, which takes t
36
36
When the `new` keyword is used with a constructor function, it creates a new object, sets the `this` keyword to refer to that object, executes the code inside the constructor function (which typically sets up the object's properties), and then returns the new object.
37
37
38
38
39
-
### Explain Object Annotations in javascript
39
+
### Explain Object Annotations
40
40
Object Annotations in javascript are a way to define and initialize objects. An object is created by enclosing key-value pairs within curly braces `{}`. The keys represent the properties of the object and the values represent the values of those properties.
41
41
42
42
There are two ways to add properties to an object using object annotations:
@@ -69,7 +69,7 @@ const myObject = {
69
69
In this case, the properties are defined inside the curly braces `{}` separated by commas `,`.
70
70
71
71
72
-
### Explain Dot annotation in javascript
72
+
### Explain Dot annotation
73
73
In JavaScript, dot notation is a way to access properties and methods of an object using the dot (.) operator. Using dot notation, you can access properties and methods of an object by specifying the object name followed by a dot and then the property or method name.
74
74
75
75
For example, if you have an object called "person" with properties "name" and "age", you can access the name property using dot notation like this:
Note that dot notation only works for accessing properties and methods that have valid identifier names. For properties or methods with special characters or reserved words in their names, you must use bracket notation instead.
101
101
102
102
103
-
### Explain Bracket annotation in javascript
103
+
### Explain Bracket annotation
104
104
Bracket annotation in JavaScript is a way of accessing an object's property using square brackets and a string key instead of the traditional dot notation. For example, instead of writing `object.property`, you can write `object['property']`. This is useful when the property name is dynamic or contains special characters that are not valid as identifier names.
105
105
106
106
For instance, if you have an object `myObj` with a property whose name is stored in a variable `propName`, you can access it using bracket annotation like this: `myObj[propName]`. Similarly, if the property name contains special characters like spaces or hyphens, you can use bracket annotation to access it: `myObj['special-prop']`.
107
107
108
108
Note that while most objects in JavaScript support bracket annotation, there are some exceptions, such as primitive values (e.g., strings, numbers) and some built-in objects like `Math` or `Date`.
109
109
110
110
111
-
### Explain Object properties : Key and Value in javascript
111
+
### Explain Object properties : Key and Value
112
112
In JavaScript, an object is a collection of key-value pairs. The "key" in an object refers to the unique identifier that is used to access its corresponding "value".
113
113
114
114
For example, consider an object representing a person:
In JavaScript, an array inside an object is a way to store multiple values in a single property of an object. This property can be accessed using the dot notation or square bracket notation.
136
136
137
137
For example, let's say we have an object called "car" with properties such as "make", "model", and "year". We can add an array called "features" that includes additional information about the car, such as its color, engine size, and transmission type.
So, by using an array inside an object, we can organize related data together and easily access it when needed.
158
158
159
159
160
-
### Explain Function inside an Object in javascript
160
+
### Explain Function inside an Object
161
161
In JavaScript, objects can contain functions as properties, which are called "methods". These methods can be accessed and invoked using dot notation.
162
162
163
163
For example, consider an object representing a car:
@@ -204,7 +204,7 @@ let car = {
204
204
Here, `this.make` and `this.model` refer to the `make` and `model` properties of the `car` object.
205
205
206
206
207
-
### Explain Uses of this inside an Object in javascript
207
+
### Explain Uses of this inside an Object
208
208
In JavaScript, `this` refers to the current object that a method is being called on, or the object that a function is invoked with. It allows you to access and modify properties and methods of the object within which `this` is used.
209
209
210
210
Some common uses of `this` inside an object include:
@@ -220,7 +220,7 @@ Some common uses of `this` inside an object include:
220
220
Note that the value of `this` depends on how a function is called. When a function is called without an explicit context (i.e., as a standalone function), `this` refers to the global object (e.g., `window` in the browser). To avoid this, you can use the `bind`, `call`, or `apply` methods to explicitly set the value of `this`.
221
221
222
222
223
-
### Explain Object functions Keys(), Values(), entries() in javascript
0 commit comments