0

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?

Marcin Kurpiel
  • 175
  • 1
  • 8
  • If you know it's an arrow function already, what are you confused about? Seems like you already know it's a function and not a `bool`. –  Aug 03 '16 at 14:52
  • Duplicate of: http://stackoverflow.com/questions/24900875/whats-the-meaning-of-an-arrow-formed-from-equals-greater-than-in-javas?noredirect=1&lq=1 – Paul Aug 03 '16 at 14:56
  • `entityMap => !!entityMap` is equivalent to `function ( entityMap ) { return !! entityMap; }` – Paul Aug 03 '16 at 14:56
  • Ok, so what actually is createHasDataGetter returning? Is it bool? Returned by arrow function? Why return statement has 2 argumets (array of strings and function returning bool) – Marcin Kurpiel Aug 03 '16 at 15:07

1 Answers1

3

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.

Community
  • 1
  • 1
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339