What is good practise, more readable? I was wondering what is the better way of writing? Having several variables to show the steps or rather do method chaining?

function count(string) {
    const array = string.split("");
    return array.filter(element =&gt; element === "a").length
}

function count(string) {
    return string
        .split("")
        .filter(element =&gt; element === "a")
        .length
}


Thank you in advance.
In this case I would clearly go with the more concise version 2.

In general it can improve readability to assign complex expressions to variables with meaningful names and I would always prefer this to adding a comment. However, in this case there is neither the necessity to add a comment nor is the variable name array very meaningful. Just the opposite: You have to decode the second line by looking up array one line above if you want to understand what's going on.

Personally I would shorten the code some more:

function count(string) {
    return string.split("").filter(e =&gt; e === "a").length
}


In my opinion, the name element doesn't add much information here, so you might as well write e or x. When variable scope is very short, these short names are fine. When you read this code, you will never wonder where the hell this variable e is coming from and what it means. It literally refers to something defined on the same line.