Saturday 22 December 2018

What is the value of unassigned properties of an object?

If you do not assign any value to a property, then the value is undefined.

HelloWorld.js
class Employee{
  constructor(firstName, lastName){
    this.firstName = firstName;
    this.lastName = lastName;
  }
}

var emp = new Employee();

console.log(emp.firstName + " : " + emp.lastName);

Output
undefined : undefined

Previous                                                 Next                                                 Home

No comments:

Post a Comment