0

I'm working on Typescript and I don't understand the execution of this program. What are the differences between the fixed and the dynamic parameter.

const appendEmoji = (fixed:string) => (dynamic:string) => fixed + dynamic;

const rain = appendEmoji('️')
const sun = appendEmoji('☀️')

console.log(rain(' today'))
console.log(sun(' today'))

Also I don't understand why we can pute a parameter into the rain function ?

Mo0nKizz
  • 149
  • 7
  • 1
    https://en.wikipedia.org/wiki/Currying – Ryan Schaefer Sep 29 '21 at 14:20
  • "*What are the differences between the fixed and the dynamic parameter.*" there aren't differences. The names are also misleading. These are just normal parameters. It's a curried function, though, which means that executing `appendEmoji` returns another function. Which is why `rain` and `sun` can be executed. – VLAZ Sep 29 '21 at 14:21
  • `appendEmoji` is a function that returns a function. The function it returns will prepend (not *a*ppend) the given string to its parameter when it's called. So `const rain = appendEmoji('️')` creates a function that will prepend `'️'` and assigns that function to `rain`. Calling `rain` with `' today'` results in `'️ today'`. – T.J. Crowder Sep 29 '21 at 14:21

0 Answers0