
JavaScript: The Hard Parts Q&A: Passing Functions
This course has been updated! We now recommend you take the JavaScript: The Hard Parts, v2 course.
Transcript from the "Q&A: Passing Functions" Lesson
[00:00:00]
>> Will Sentance: Okay, we're gonna have thumbs and we're gonna go and test this out in pairing through the challenges. And then we're gonna talk about why is this even possible in Java? For a language where you do not pass functions around, this is gonna feel very, very uncomfortable. If you want a language that the idea of passing a function into another function, is gonna feel very uncomfortable in JavaScript, a core part of Java.
[00:00:25] So we're gonna see why after the pairing, but first, do you wanna phrase it as a question?
>> Speaker 2: I don't understand why instructions becomes function multiplied by two. Is it just because it's the second parameter that's passed?
>> Will Sentance: It's exactly that, damn right. So why does array become 1, 2, 3?
[00:00:47]
>> Will Sentance: So when we define the function, so with functions, there's two stages, right? There's the, this is what it will do if you use me. This is a definition. It's like the, if you ever use me, this is what I will do. And there is the running it.
[00:01:01] Can you gesture which bit's the definition? Which bit of the copy array manipulate? Which version is the manipulation? Lindsay, which one of these is a definition?
>> Lindsay: The top one.
>> Will Sentance: The top one, exactly. copyArrayAndManipulate, that's like, this is what I'll do if you ever run me. This is my description, this is what my functionality is.
[00:01:26] That's general, it's generic. It says ultimately, I'm going to run this functionality on some data, some numbers, or some strings, or some words, or whatever. I'm gonna run it on some data, but I don't yet know what that data is going to be, right? Because that's the whole point of having a function is I want to be able to use it on all different types of data.
[00:01:44] So leave instead some blanks, some placeholders for that data. And then when you do run me, and where am I running copyArrayAndManipulate, Lindsay?
>> Lindsay: The bottom line.
>> Will Sentance: How do I know I'm running it?
>> Lindsay: With the parentheses.
>> Will Sentance: With the parens, that's where I fill in my placeholders.
[00:02:02] So my blanks, so array is a blank, I fill it in with what?
>> Lindsay: 1, 2, 3.
>> Will Sentance: And the instructions are blank, I fill it in with? And the reason is just the ordering, you're spot on, it's just the ordering. Okay, does that answer the question? Excellent, good clarification.
[00:02:14] All right, folk, at this point we're gonna get back to the pairing, work through the challenges. Map with, and for each make sure you try and do them. I'm gonna have a look at how you reach doing them, and then we will talk about how is this even possible.