What does this mean?
Y = ()=> { return + (X) }
It’s from React-Strap code…
What does this mean?
Y = ()=> { return + (X) }
It’s from React-Strap code…
It can be read as:
Assign to Y an anonymous function that will return
the result of attempting to convert X to a number.
Or in example:
X = "3"
Y = ()=> { return +(X) }
Y() // 3
The conversion is done with what is called a unary plus.
Hope this helps.
personal note: weird function that convert a fixed value (X) rather than an input.
convert a fixed value (X) rather than an input.
A fixed value? Isn’t X a variable in a wider scope…?
console.log(+'');
// expected output: 0
That’s curious…
Yes, it would have to be, because it isn’t declared inside the scope of the function, but without without being able to see any other code, it’s not possible to say what it is. All that can be inferred from the code you posted is that it’s a function that takes some value that’s outside the function and tries to convert it to a number
Obviously it’s in a wider scope but is it a variable or a fixed value set at the time the function was assigned?
Well, it’s always a variable, it’s a value assigned to the variable named X
. But as it can’t be inferred from the code posted, that’s unknown.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.