Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Examples on Employee Object

Examples on Employee Object

Example 10:

Create an object called Employee with the properties

  • ‘name’ ( String)
  • ‘age’ (number)
  • ‘position’ (String)
  • ‘Salary’ (number)
  • ‘contact’ (String)
  • ‘workDays’ (array)
  • ‘getEmployeeInfo’ (Object Method)
  • The values are given as: John, 28, Cashier, 38000, john.relstore.com, [Monday, Wednesday, Friday].
  • The method should return John works as a cashier and earns 38000 per month
const Employee = {
  name: "John",
  age: 28,
  position: "Cashier",
  salary: 38000,
  contact: "john.relstore.com",
  workDays: ["Monday", "Wednesday", "Friday"],
  getEmployeeInfo: function () {
    return `${this.name} works as a ${this.position} and earns ${this.salary} per month`;
  },
};
console.log(Employee.getEmployeeInfo());

Output

Loading

Views: 56

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments