In JavaScript, an object is a data structure that allows you to store collections of data and more complex entities. Objects are key-value pairs, where each key (also called a property) is associated with a value. The values can be of any data type, including other objects and functions.
The most common way to create an object is by using an object literal:
let person = {
name: "John",
age: 30,
isStudent: false,
greet: function() {
console.log("Hello, my name is " + this.name);
}
};
Another way to create an object is by using the Object
constructor:
let person = new Object();
person.name = "John"
person.age = 30
person.isStudent = false
person.greet: function() {
console.log("Hello, my name is " + this.name);
}
We can also create object of a class and we have seen that example in our last session
class Person {
}
let person = new Person();
person.name = 'John';
person.age = 30;
console.log(person.name);
console.log(person.age)
We can also create object of a function because there was no concept of class in the earlier version of javascript. ES6 version of javascript introduced classes.
function person() {
}
let p = new person();
p.name = 'John';
p.age = 30;
console.log(p.name);
console.log(p.age)
console.log(person)
console.log(person.name)
console.log(person.age)
console.log(person.isStudent)
console.log(person["name"])
console.log(person["age"])
console.log(person["isStudent"])
person.greet()
console.log(Object.keys(person))
console.log(Object.values(person))
console.log(Object.entries(person));
person.name = "Jack"
person["age"] = 31
person.address = "123 Main Street"
delete person.isStudent;
for (let key in person) {
console.log(key + ": " + person[key]);
}
Mostbet Turkey: Profesyonel Musteri Destegi
Heyecan Verici Kazanclar icin Gates-of-Olympus Slot
Difference between Functions and Methods in Javascript Before discussing the difference between a function and…
Objects, Classes and Constructor in Javascript Classes and Objects A class in any programming language…
We will start from object oriented programming basics like What are different concepts in Object…