adsterra

Objects in Java Script | Functions with Objects

Objects



In JavaScript, an object is a standalone entity, with properties and type. Compare it with a cup, for example. A cup is an object, with properties. A cup has a color, a design, weight, a material it is made of, etc. The same way, JavaScript objects can have properties, which define their characteristics.
Example:
//declare object
let video ={
    title:'Loops in javascript',
    videoLength : '15',
    videoCreator:'Preet',
    Description:'This is a Video Description'
}
console.log(video);
console.log(`Hi new video on ${video.title} is 
created by ${video.videoCreator}`)
//video is the objects name and .title is its property to access
//the value of particular property



Objects with Function:

let myTodos ={
    day:'Monday',
    meeting:0,
    meetDone:0,
    addMeetingfunction(num){ //addMeeting is a function name
      this.meeting =this.meeting + num
        //console.log(this) 
//this keyword refer to current class veriable 
    },
    Summaryfunction(){
return `U have ${this.meeting} of meeting today`
    }
}
myTodos.addMeeting(5)//passing value
console.log(myTodos.Summary())

E

Post a Comment

0 Comments