0

I stumbled with the following JavaScript code:

  var Employee = function (entity) {
        var employee = this;

        entity = entity || {};

        employee.employeeId = entity.EmployeeId;
        employee.email = entity.Email;
        employee.firstName = entity.FirstName;
        employee.lastName = entity.LastName; // ....

But I couldn't understand the following sentence:

 entity = entity || {};
Amr Reda
  • 582
  • 5
  • 18

1 Answers1

2

|| is the OR statement in JavaScript. Your function receives entity as variable. When entity is null or undefined, your function will fill it up with empty object which is the same as {}.

Thomas Bormans
  • 4,558
  • 5
  • 30
  • 46