I came across this line of code recently, and want to understand what it means and does, as my javascript-foo is not that hot :
if ((+!!config.template) + (+!!config.templateUrl) !== 1) {} from what I can gather, it is checking to see if either option is set (so either template, or templateUrl must be set, not both or none)
so, if config.template was set,
- +config.template would not work (template is not a number)
- !config.template would return false (-1)
- !!config.template would return true (0)
- +!!config.template would therefore return 1
if config.template was not set,
- !config.template would return true (0)
- !!config.template would return false (-1)
- +!!config.template would therefore return 0
if then you were to apply the same to config.templateUrl , you would end up with 1 if set, 0 if not
So the final test is to see if the sum of config.template and config.templateUrl is 1 (ie one or the other is set)
Is this valid reasoning ?
+(true) === 1and+(false) === 0if (!config.template === !config.templateUrl) {}. It looks much simpler that way.