Objects in the javascript: for beginner to expert level


Definition: Objects are the collection of key, value pair
let me explain by taking a example let see we stire the pronoun with the noun
Name: “hackthic”
work: “programming”
i don’t know if you get it or not but I hope you get it;
let's take the programming example;
const object1{
name: "hackthic",
work: "programming"
gender: "male" //of course
islearning: true
};
console.log(object.name)
//output: hackthic
Note: key is always in string and the value can be any datatype. if we want to access the the value of object then we have to write the name of object and then add dot(.) then the key name. // object_name.key
Method in Javascript
object contains a function inside called a method.
example
const car{
brand: "nano",
startEngine: function(){
console.log("engine started")
},
isGood: true
};
car.startEngine(); //output: engine started
“This” keyword in object
it refer to the current object
const user{
name: "hackthic",
greet(){
console.log(`namaste ${this.name} chalo chai pi ke aye`)
}
};
user.greet();
Prototype and classes in javascript
object inherited properties/methods from prototypes. classes are blueprint of the object.
class Dog{
constructor(name){
this.name=name;
}
bark(){
console.log(`${this.name} say woo!`};
}
}
const myDog = new Dog('rex');
}
}
myDog.bark();
this is what i learn in beginning and if you are want to learn more about the object the see the “chai aur code javascript playlist” and “Namaste javascript by Akshay saini”
if I make some mistake then please correct me in the comment. guys i know my grammar not much good so please suggest me some content.
Subscribe to my newsletter
Read articles from hackthic directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
