JavaScript Object Methods

1/22/2020 2:21:59 AM

In this JavaScript code we discourse the JavaScript object method. Basically, JavaScript object method responsible to assign or print the object value. JavaScript object method present under the object and it call by the object name then access the object. The JavaScript object method is very important for the object property get or set the value. If we detect the object itself property or variables then we write “this” keyword. Now given bellow the JavaScript object method code and explain the code:

<!DOCTYPE html>
<script type="text/javascript">
    //object with method 
var mYobj = {
  id     : 0,
  Name: "",
  NameAndId : function(name) {
    return"My Name: "+ this.Name + ", my id: " +;
// Show data from the object:
 console.log(mYobj.NameAndId("Farhan Sakib"));

In this code we first create an object then the object contains the two-property name as id, name. this name property assigns by the parameter overload and return the id and name value. Then we use the “console.log” for print the values out of the object.