T
T
Topsky2017-04-09 10:58:35
JavaScript
Topsky, 2017-04-09 10:58:35

How to understand how return works in a code example?

https://github.com/fent/node-ytdl-core
There is such code in the examples on that hub

ytdl(url, { filter: function(format) { return format.container === 'mp4'; } })
  .pipe(fs.createWriteStream('vide.mp4'));

I don't understand how return format.container === 'mp4';
I tried to check what was happening myself, I did forEach, for, an ordinary if with such a condition, but it’s not clear what is happening in this retarder, please explain, please, or tell me what it’s called in general, otherwise I can’t google correctly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D3lphi, 2017-04-09
@Topsky

Let's format the code to make it easier to read:

// ...
{
    filter: function(format) {
         return format.container === 'mp4';
    }
}
// ...

Here, the boolean value true/false will be returned from the function to the filter property, depending on whether format.container is equal to the string 'mp4'.
The way format.container === 'mp4' works is this: it's a comparison operator, so this expression returns true if the equality is true and false if the equality is false.
'str' === 'string' // false
'str' === 'str' // true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question