Marcin Kurpiel
Marcin Kurpiel

Reputation: 175

What does this arrow function JavaScript code mean?

I am trying to understand HomeAssistant frontend source code. I have found function definition that I dont uderstand well. I dont understand this syntax (model.entity is a string)...

export function createHasDataGetter(model) {
  return [
    ['restApiCache', model.entity],
    entityMap => !!entityMap,
  ];
}

It looks like smth like:

return [[string, string], bool]?

What is exacly teturn type of this function? Is this just bool? If yes, does it mean entityMap is string array?

Upvotes: 0

Views: 62

Answers (1)

Sinan Ünür
Sinan Ünür

Reputation: 118166

See "Truthy" on MDN:

In JavaScript, a truthy value is a value that translates to true when evaluated in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except for false, 0, "", null, undefined, and NaN).

entityMap => !!entityMap maps entityMap to a canonical boolean value, true or false. See also What is "!!" in C?.

If entityMap has a truthy value, then !entityMap is false, and !!entityMap is true.

If entityMap has a falsy value, then !entityMap is true and !!entityMap is false.

Upvotes: 3

Related Questions