-1

I am studying javascript and i was wondering if there is any way of passing a function return to another function. for instance, let's say i have this function title.toLowerCase().split(" ").join("-") and i want to immediately pick it's return and pass to another function, like (test) => console.log(test) .

What the second function will eventually do is to check if there is any - at the beginning of the string, and remove it case positive, i know there are other ways of doing this, but i want to know if is there a way with any function immediately after the return of the first function.

something like

title.toLowerCase().split(" ").join("-")}{(word) => {
                                            console.log(word);
                                            //checkIfContains-
                                            //remove-
                                            return newWord}};
user202684
  • 31
  • 4

1 Answers1

0

Coding is like basic mathematics. If you want to use the result of function A in your function B, you should go for B(A). Like I said basic maths, the function starts with A "inner function" and ends with B "outter function"

I couldn't really understand what you meant exactly with your example.

let's say i have this function title.toLowerCase().split(" ").join("-") and i want to immediately pick it's return and pass to another function, like (test) => console.log(test) .

You can simply do it like I told you above:

console.log(title.toLowerCase().split(" ").join("-"));

In this case, console.log() is your B function and title.toLowerCase().split(" ").join("-") is your A function.

MrJami
  • 176
  • 11
  • I understood your point, but what if instead of a console.log, i want to do a whole function like the one in the exemple? {(word) => { //checkIfContains- //remove- return newWord}}; in that case, is there any way of passing {(title.toLowerCase().split(" ").join("-")) => { //checkIfContains- //remove- return newWord}}; ? – user202684 Jan 22 '21 at 15:22