JavaScript - Functions - Return

  Рет қаралды 92,575

Coding with Dave

Coding with Dave

Күн бұрын

Пікірлер: 246
@JCL-nu4ge
@JCL-nu4ge 4 жыл бұрын
What the heck. This was posted 3 years ago and am now barely seeing it!? This was the most basic, YET thorough explanation on a return
@coding-with-dave
@coding-with-dave 4 жыл бұрын
Thanks. That means a lot :)
@SaeleeSaan
@SaeleeSaan 3 жыл бұрын
seriously.
@dr_corrupt1014
@dr_corrupt1014 2 жыл бұрын
@@coding-with-dave bro you explain it best what an amazing explanation
@kira3821
@kira3821 Жыл бұрын
me too, i just started js last month and this was very helpful, im glad ive stumbled on this video, and this was 5 years ago lmao
@ibraheemmudasser4810
@ibraheemmudasser4810 Жыл бұрын
And i am seeing this after6 years😂
@rheavictor7
@rheavictor7 2 жыл бұрын
This is the one. I have a hard time understanding the "why" for using return, and now I'm starting to get the idea. My job is now to test it so I can conclude things by myself, thank you so much!
@rehanmalik2898
@rehanmalik2898 3 жыл бұрын
A nice simple way to explain the return concept. As a fresher in JS it was very valuable lesson for me. Thanks
@lorenzejay3296
@lorenzejay3296 4 жыл бұрын
After watching many reviews, this was the one for me. I understand it now. Thank you
@coding-with-dave
@coding-with-dave 4 жыл бұрын
Thank you Lorenze. I'm so glad it helped.
@k.iskandar
@k.iskandar 3 жыл бұрын
I bought a udemy course and the tutor didn't explain return function particularly well. Your explanation just made it so much easier to understand. Thank you very much. You've earned a subscriber.
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Thanks for the kind words.
@krithiksingh
@krithiksingh 2 жыл бұрын
Same problem here, I feel like he explained the return function very poorly.
@aavezshaikh143
@aavezshaikh143 Жыл бұрын
Is that course by Angela on udemy ?
@ronkeylinarizini8049
@ronkeylinarizini8049 4 жыл бұрын
I'm pretty much gonna echo what everyone else has been saying; best tutorial I've found yet. Thank you!
@coding-with-dave
@coding-with-dave 4 жыл бұрын
Thank you very much for taking them time to say that.
@ulijibkadelm318
@ulijibkadelm318 3 жыл бұрын
I love you bro. I was literally confused after watching so many tutorials about return because they not straight to the point. But now I understand it, Thank you very much. You earn a new subscriber and you deserve more
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Appreciate the kind words. I'm glad I could help.
@revanthv1319
@revanthv1319 4 жыл бұрын
i dont know why you did not get more subcribers but i understood it very clearly thank you bro
@coding-with-dave
@coding-with-dave 4 жыл бұрын
Thanks. I'm happy that it helped.
@ThePickleVR
@ThePickleVR Жыл бұрын
Thank you. I've been looking all over for an answer for this. I just couldn't understand untill watching this.
@coding-with-dave
@coding-with-dave Жыл бұрын
Glad I could be of assistance to you. Keep getting better.
@shahulz4705
@shahulz4705 3 жыл бұрын
Crystal clear after 7hours of searching a same concept tanq bro from India:)
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Glad it helped. Happy coding :)
@bryallen11
@bryallen11 Ай бұрын
I managed to get to 2:46 and realized that I knew less about return than I did before.
@bryallen11
@bryallen11 Ай бұрын
Teaching is an art that some people have and some people don't.
@bryallen11
@bryallen11 Ай бұрын
Some people are able to make the complex easy and understandable, others are apt to make the easy and understandable very complex.
@DavidHust
@DavidHust Ай бұрын
hopefully it was helpful. Is there anything that's still unclear that I can help you with?
@yammmaya3838
@yammmaya3838 2 жыл бұрын
I 've been struggling to undertstand the concept of return. Your explaination was just what I was looking for. Thank you so much!!! You made it super clear!🤩🤩
@coding-with-dave
@coding-with-dave 2 жыл бұрын
I'm glad it help. Keep trying to learn one new thing a day. Even if it's small.
@rahxephon76
@rahxephon76 4 жыл бұрын
Thank you so much for this video, by far the best explanation I've found on this topic.
@purple7770
@purple7770 Жыл бұрын
I appreciate the way you describe your work! I think this is one of the best beginner friendly channels on youtube!
@coding-with-dave
@coding-with-dave Жыл бұрын
Wow. That's very nice of you to say. Glad it helped.
@tyreesewray9190
@tyreesewray9190 11 ай бұрын
Bro thank you so much, I felt so slow trying to understand the return function. Earned a like and subscribe
@coding-with-dave
@coding-with-dave 11 ай бұрын
I know that feeling. Happy that I could help because I know the struggle is real sometimes. Nice job pushing forward through it all. Coding is way more fun when you add to your toolbox of skills.
@mimiraks
@mimiraks 2 жыл бұрын
Remarkable!! I was stumped that my VS Code couldn’t work with return but now I understand! Mucho gracias
@Bread-vk8fl
@Bread-vk8fl 2 жыл бұрын
So basicly when you use RETURN you must have a variable that storages its value. Now it makes sense for me. Thank you very much!!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
That's a good way to think of it. Just to add another level of understanding, technically, you don't need to make a variable because you could write something like `return num * 2`, where num is a parameter that was passed into the function. But you definitely could write the same thing using a variable, `let result = num * 2`, `return result`.
@beesleyrc759
@beesleyrc759 4 жыл бұрын
Thanks you! I was having trouble understanding returns. You made it simple to understand.
@khaung4413
@khaung4413 Жыл бұрын
I was struggling with retune logic and you got me 100% clear about it
@coding-with-dave
@coding-with-dave Жыл бұрын
Great to hear! Those return functions can be tricky. Keep rockin' it out.
@toppu10animes
@toppu10animes 3 жыл бұрын
Wtf, you're a genius at teaching
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Thank you so much. That means a lot. Happy coding.
@millanferende6723
@millanferende6723 3 жыл бұрын
I actually like it. It sort of makes sense why this function needs a return. Because otherwise it just gets element by ID, but doesnt DO anything with it. It got it and ok it's done. But RETURN, makes sure that it passes this value back, to be used. function $(X) {return document.getElementById(X)}; BTW, the above function makes sure that if you ever want to get element by ID, all you have to do in your code is write $("anyIdName") and you would have called that function and selected the ID that you want. :) Super useful trick!
@abhishek_23685
@abhishek_23685 Жыл бұрын
Finally understood why and when to use return function. Thanks!
@coding-with-dave
@coding-with-dave Жыл бұрын
Let's goooo. Great to hear. Happy coding!
@Mohammed-od4ju
@Mohammed-od4ju 4 жыл бұрын
Thanks! You have been given the ability to teach.
@coding-with-dave
@coding-with-dave 4 жыл бұрын
Thanks. That's very nice of you to say.
@VikOtis-Deploys-zl1bz
@VikOtis-Deploys-zl1bz Жыл бұрын
I could follow you the whole way. Thanks for that, always good.
@cilcil2731
@cilcil2731 4 жыл бұрын
This was very helpful! I was researching on how return(); works and this answered my questions. Thanks a lot!
@jjcoolman59
@jjcoolman59 2 жыл бұрын
It took me a minute!! But it finally clicked. I’m really new and js and I think the explanation was amazing!!!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Thanks a lot. I appreciate you taking the time to write that.
@billyjayamunga
@billyjayamunga 3 жыл бұрын
I finally filled the gap in my understanding of return. Thank you.
@coding-with-dave
@coding-with-dave 3 жыл бұрын
I'm glad I could be a part or that! Happy coding.
@dineshrobins9111
@dineshrobins9111 2 жыл бұрын
That is so simple and neat,,,adds value to our education,,,Thankyou.
@ivanurbina2422
@ivanurbina2422 2 жыл бұрын
Awesome tutorial!!! I appreciated your explanation. This is what I was looking for. I suscribed.
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Thanks for giving me feedback. Glad it helped. Happy coding.
@naheeddeedar2792
@naheeddeedar2792 3 жыл бұрын
Idid many practice but after watching this video i really happy
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Great to hear. I'm glad it helped. Happy coding.
@okolipeace774
@okolipeace774 Жыл бұрын
Really needed this video. Thanks for explaining it in a simple way
@coding-with-dave
@coding-with-dave Жыл бұрын
Thanks for the feedback. Happy coding.
@BlackZero880
@BlackZero880 3 жыл бұрын
hey thank you man it was like 1+1 explaination to me...you made it cup of cake
@zannatul23
@zannatul23 Жыл бұрын
one of the best tutorial on return!
@coding-with-dave
@coding-with-dave Жыл бұрын
Much appreciated. Happy coding.
@rajesh.geesala7565
@rajesh.geesala7565 Жыл бұрын
thank you , you deserve love .. lots of luv from India ❤❤
@coding-with-dave
@coding-with-dave Жыл бұрын
Appreciate the love.
@krithiksingh
@krithiksingh 2 жыл бұрын
I was not understanding the return statement at all but your video made it feel so easy lol, thank you!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
That's awesome. Returning values is such an essential skill so great job on persevering and figuring it out.
@krithiksingh
@krithiksingh 2 жыл бұрын
@@coding-with-dave Yessir, ty. Turns out my instructor did a very poor job at explaining its functionality.
@bir.hossan
@bir.hossan Жыл бұрын
I was struggling with" return concept.Thanks a million for the awesome explanation! 🙌 Your video made it so clear that I finally get 'return' in JavaScript, just like a function returning the value it promised. Keep the great content 'returning'! 😄💻🚀 #CodeWithDave"
@coding-with-dave
@coding-with-dave Жыл бұрын
I see what you did there 😉
@bir.hossan
@bir.hossan Жыл бұрын
Bro your explanation was so simple and helpful for a beginner like me.@@coding-with-dave
@coding-with-dave
@coding-with-dave Жыл бұрын
@@bir.hossan Thanks for the feedback and kind words. Keep learning, keep coding, make great stuff!
@nicox55
@nicox55 2 жыл бұрын
dude!! thanks alot i was looking cause i got that function in my class and how my mate explaint it to me was really confusing. now i totaly get it. thanks like and suscribe to your channel mate.
@dnrevan778
@dnrevan778 2 жыл бұрын
Thank you. I understand this better now!!! So pumped
@Kevin_722
@Kevin_722 3 жыл бұрын
man i was confused about what return function meant but after watching this vid I was shocked by how amazinly it was explained and how quickly I understood. Keep it up!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Great to hear. Have fun learning more!
@fredianriko5648
@fredianriko5648 4 жыл бұрын
for anyone who still confuses, the number he inputs at the prompt window is assigned to the "n1" of the "multiply()" function, so as he put example when he runs the code, the prompt window pop up asking the user to give a number input, he inputs "7" so, the value of "n1" in the "multiply()" function becomes 7, and the sum function is doing its operation which is "+" using the value from the variable that already defined in the first and second line, sum() = 7 multiply() = 6 var product = multiply( 6 , 7 ) console.log(product) the result is = 42 as shown in the video
@papagrey
@papagrey 2 жыл бұрын
Man this is way better than skillshare courses I doing, in my opinion they are useless compare to this lesson. Damn, I was trying to understand Return many times and could not get it at all and here after watching few times I totally get it now!! Thank you stranger!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Glad I could help. I usually have to watch a couple videos to really understand a concept. Keep having fun coding!
@papagrey
@papagrey 2 жыл бұрын
@@coding-with-dave Thank you very much and I hope you going to keep teaching people coding in the easy way!
@eitanleiberman7334
@eitanleiberman7334 2 жыл бұрын
Return was explained very good! Thanks!
@chimsbeatzzedstar
@chimsbeatzzedstar Жыл бұрын
Properly explained 🤩
@sina9881
@sina9881 2 жыл бұрын
Thank you for this really cleared my confusion
@Escko
@Escko 2 жыл бұрын
great clear explanation brother...thank you!!!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
You're welcome. Thanks for letting me know it was helpful.
@GovilX
@GovilX 3 жыл бұрын
this explanation made perfect sense, thank you.
@coding-with-dave
@coding-with-dave 3 жыл бұрын
You're very welcome.
@wellaway3303
@wellaway3303 Жыл бұрын
this is very comprehensive thank you!
@inactiveaccount4829
@inactiveaccount4829 3 жыл бұрын
These are times that I truly wish I had a tutor.. sad. I'm about to watch your video, so I hope this helps, but I'm making my own functions now and I'm struggling to understand when and WHY to put a return statement. I'm putting return statements in the wrong places and it makes me think that my ENTIRE code is messed up, when really I have the return statement within the wrong set of brackets.
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Functions that return a value can be tricky for a while. I always think of return statements as being the last thing a function does. That doesn't mean it should be at the bottom, but whenever you are done with a function you could have a return statement. You can also have multiple return statements depending on when and what you want to return. Keep trying and testing things out. You got this!
@AllKindzzzz
@AllKindzzzz 4 жыл бұрын
Nice explanation, finally made it click for me. Cheers!
@coding-with-dave
@coding-with-dave 4 жыл бұрын
I'm glad it helped.
@tuan2686
@tuan2686 2 жыл бұрын
very well explained thank you so much :)
@BusyAsBee1738
@BusyAsBee1738 3 жыл бұрын
Hi, amazing video! 3:01 Can u also just plop the add function down as multiply function parameter? I know it's probably not the best practice but I still want to know
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Yes, you can. It will just be a bit more difficult to read.
@boladeoluwatobiloba2024
@boladeoluwatobiloba2024 4 жыл бұрын
Thank you for breaking this down
@coding-with-dave
@coding-with-dave 4 жыл бұрын
You're welcome Bolade.
@tofulosophy
@tofulosophy 5 жыл бұрын
nice explanation. So does that mean for a 'return' to be useful, it must always be returned to a variable?
@coding-with-dave
@coding-with-dave 5 жыл бұрын
No, but it may be more useful when returned as a variable because you may use that value more than once throughout the rest of your program. For example, if you just want to figure out the largest number in a list of numbers, then returning it, and not assigning it to a variable, is fine; but if you wanted to use that largest number later, then assigning it to a variable would be best.
@tofulosophy
@tofulosophy 5 жыл бұрын
@@coding-with-dave thanks!
@AllKindzzzz
@AllKindzzzz 4 жыл бұрын
@@coding-with-dave What would returning the largest number even do if you didn't capture the return in a variable? This is the only part of the return I don't quite understand.
@coding-with-dave
@coding-with-dave 4 жыл бұрын
@@AllKindzzzz Good question. The answer is... nothing really. I mean the code will still run, but it would be useless code because you would just have a line that would say something like 12; in your main program.
@adolfjamesurian6510
@adolfjamesurian6510 4 жыл бұрын
My one big question in return statement is what do you mean by return value? Like where will it return and how/where is it restoring the value
@adolfjamesurian6510
@adolfjamesurian6510 4 жыл бұрын
Hope you noticed this very soon
@coding-with-dave
@coding-with-dave 4 жыл бұрын
Returning a value means that the function that's created will do something and the value you want to get FROM that function will be available outside the function. For example, if I make a function called fullName(firstName, lastName) that combines a person's first and last name, I would want to be able to call that function, whenever I want, in my main program and it would always give me (a.k.a. "return") a person's full name. So in this case the function returns a String. To go further with the example, if I called the function fullName("Steve", "Martin") then that would end up being replaced (returned) in my code with the value "Steve Martin". Sorry if this is too wordy. Here is a example that may help. Let me know if it doesn't. codepen.io/dhust/pen/yLOKWdp?editors=0012
@adolfjamesurian6510
@adolfjamesurian6510 4 жыл бұрын
Ohhhh so return likely means creating a value to return to where its function is called
@coding-with-dave
@coding-with-dave 4 жыл бұрын
@@adolfjamesurian6510 Yeppers. You got it!
@ashadcosta8756
@ashadcosta8756 3 жыл бұрын
Why isn't the input considered as a string ? Whenever we take input from the user, using prompt isn't the value always stored as a string, irrespective of a numeric value ?
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Great question. That is usually true, like in Python. These two lines of code will out that value is a "number": var value = 4; console.log(typeof value); These two lines of code will print that it's a "string": var value = "4"; console.log(typeof value);
@chibifrank1340
@chibifrank1340 2 жыл бұрын
I understood finally thanks but when I changed the multiplication to addition sign it just put the two number beside each other without adding it
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Can you paste your code here?
@chibifrank1340
@chibifrank1340 2 жыл бұрын
@@coding-with-dave sure var right = 5 var left = 5 function final ( x,y ){ var add = (x+y); return add; } function pol (a , b){ console.log(a+b); } var add = final (right,left); var input = prompt("Input your age"); pol(add, input);
@coding-with-dave
@coding-with-dave 2 жыл бұрын
@@chibifrank1340 Thanks for posting this. The prompt() function gives us (returns) a String. When we use + signs with Strings, all it does is put the two String next to one another, which is what is happening. Since you are already adding 5 and 5, which is 10, and then you input a 4 into the prompt, it will print "10" + "4" which is "104". I should have converted the String into an integer, using parseInt(), and then multiplied the numbers. I added a line and then changed another line. Hope this helps. var right = 5 var left = 5 function final ( x,y ){ var add = (x+y); return add; } function pol (a , b){ console.log(a+b); } var add = final (right,left); var input = prompt("Input your age"); var inputInt = parseInt(input); pol(add, inputInt);
@alejandrocanales5129
@alejandrocanales5129 4 жыл бұрын
Great explanation
@Digzaary
@Digzaary 2 жыл бұрын
i hit like number 1000 thx man
@Quidoute
@Quidoute 3 жыл бұрын
oh boy, I finally understand this function
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Heck yeah! Keep that learning going :)
@scottlaking
@scottlaking 3 жыл бұрын
Do you have a more elementary version of this topic? At my nube level, I wonder why you chose to use "(n1 , n2) " to "function add". are these just random tags that you chose or are they a part of JS? Why do we need them?
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Sorry for the late response. Yes, n1 and n2 are just random names I chose. It could be (num1, num2) or (cat, tree). We need these because I decided that the add function would add two numbers.
@jlambert12013
@jlambert12013 2 жыл бұрын
Best explanation.
@SpaceDoodle2008
@SpaceDoodle2008 Жыл бұрын
This helped me so much! 🤗
@coding-with-dave
@coding-with-dave Жыл бұрын
Great to hear. Keep pursuing those skills.
@marwanashraf9036
@marwanashraf9036 Жыл бұрын
Thank you very much sir you really helped me alot
@bhp9415
@bhp9415 7 ай бұрын
thanks it helped understand better this return function
@coding-with-dave
@coding-with-dave 7 ай бұрын
Glad it helped. Happy coding :)
@GretSeat
@GretSeat 2 жыл бұрын
I still don't understand what "return" is. This didn't really help. Like... does it just... "hold" a number...? And if so, why don't you just use a variable? why return?
@coding-with-dave
@coding-with-dave 2 жыл бұрын
You are right in that the function does have data that it holds. Any calculations that function does, or variables that you create in that function, will only exist while that function's code is running. After the function has completed its last line of code, all that data gets "deleted". So if all that work the function did ends up just being deleted, then what's the point? That's where a return statement can help. If we need to get information from a function back to the main program, like the result of an equation that's being stored in a variable, then we need to return that variable's value by using a return statement. Maybe that helped? If not, let me know.
@ikigu
@ikigu 2 жыл бұрын
Thank you! Been struggling to understand what return was.
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Glad it helped. Happy coding.
@koraykurtaran5793
@koraykurtaran5793 2 жыл бұрын
Thanks! Great explanation!
@assancamara7178
@assancamara7178 7 ай бұрын
Tanks a lot the video was so helpful
@stevenberg8719
@stevenberg8719 3 жыл бұрын
great explanation! THANK YOU!
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Thank you for the feedback.
@gallyinamsterdam7273
@gallyinamsterdam7273 Жыл бұрын
Thank you for the explanation! One question: you said at 3:57 "we don't always want to print stuff out over the console every time we multiply, all we want it to do is multiply two numbers and give us the value back". What is the difference between "print the number out" and "give us the value back"? In both cases it does the same - gives us 35 in the console.
@gallyinamsterdam7273
@gallyinamsterdam7273 Жыл бұрын
Or is it just for this particular example that the outcomes are the same, but the purpose of this extra step is that we could use this "return" in the future? But for now it just gives us the same 35 because that's as far as the current call goes?
@coding-with-dave
@coding-with-dave Жыл бұрын
Printing to the console is usually meant for debugging your code, aka finding out what's going on. Usually, we want to use that number somewhere else in our program. For instance, maybe we have the price for a hamburger and we buy four of them. We can use this function to do that. But then we also need to calculate the taxes on top of that. So we would return the total price of all the hamburgers from the function, then we can take that number, call the same function but this time pass in that total and the tax rate, and then return that new, taxes total. We don't need to print anything to the console but we may want to show that on a webpage so the customer can see it. A little lengthy but I hope that helps. If not, let me know.
@gallyinamsterdam7273
@gallyinamsterdam7273 Жыл бұрын
@@coding-with-dave thank you for the explanation! It does help :)
@Pedro-bu8xd
@Pedro-bu8xd Жыл бұрын
Bravo Sir.. thanks a bunch
@coding-with-dave
@coding-with-dave Жыл бұрын
Thanks for letting me know. Happy coding.
@sallylauper8222
@sallylauper8222 3 жыл бұрын
Don't functions always return some value, even if you don't use return command?
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Great question. In JavaScript it may seem like that but that's not the case. You can test this idea using the following code: function add() { var sum = 3 + 4; } console.log(add());
@coding-with-dave
@coding-with-dave 3 жыл бұрын
The idea of functions returning or not returning a value makes more sense with a language like Java. When you make a function in Java you actually have to state what type of data you'll return, like a String or int. And if you don't want to return anything you would use the "void" keyword instead.
@matthewblasco4720
@matthewblasco4720 2 жыл бұрын
This made me a hell lot level clearer about returns. Just thanks to you! Based on my understanding after watching this video, this means that the `return` makes the function's result call-able or storable in a variable or container? right? sometime later we can use the whole function again with just the variable name right? coz i tried calling the function without the return and it just says NaN, so I guess it's right? Thank you so much!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
"this means that the `return` makes the function's result call-able or storable" - I like this thought. Never thought about it like that, and you are correct. "sometime later we can use the whole function again with just the variable name right?" - I probably wouldn't say that you "use the whole function again". The function has already been ran so it has been replaced by the returned value. That value is now stored in the variable "sum" which can be used later in your program. I like you're thinking with all of this. Keep up the good work!
@dr_corrupt1014
@dr_corrupt1014 2 жыл бұрын
best explanation everrr
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Appreciated.
@einatpilates
@einatpilates 4 жыл бұрын
great explanation! thanks!
@shahriarsohan8731
@shahriarsohan8731 11 ай бұрын
at last, finally i understood return
@coding-with-dave
@coding-with-dave 11 ай бұрын
Great to hear it helped. Returns can be quite the struggle so good job keeping at it. It's so important. Thanks for the feedback.
@shahriarsohan8731
@shahriarsohan8731 11 ай бұрын
Can you make a vid explaining the use of double function...i mean using function inside an another function?
@DavidHust
@DavidHust 11 ай бұрын
​@@shahriarsohan8731I like that idea. Seems like a natural progression.
@katherinel6448
@katherinel6448 Жыл бұрын
thank you this helped so much!
@coding-with-dave
@coding-with-dave Жыл бұрын
Thanks for taking the time to let me know. Good luck with improving those coding skills. It's so much fun.
@EngineeringLife0
@EngineeringLife0 2 жыл бұрын
Great explanation!!!!!
@TheKre8ivemind
@TheKre8ivemind Жыл бұрын
if your watching this and it doesent make sense come back a day later and pause it from time to time and code this out yourself it will make WAY more sense. i was learning about function, arguments, parameters, and returns in the same day and this seemed like gibberish. let your brain cool off1 ITS ACTUALLY NOT THAT HARD if you give yourself a break.
@coding-with-dave
@coding-with-dave Жыл бұрын
Great suggestion. Sometimes it can be overwhelming the first time. Have fun coding!
@hasansabuz
@hasansabuz 4 жыл бұрын
Allah will sure bless u my brother. This video helped me a lot
@toppu10animes
@toppu10animes 3 жыл бұрын
Nah, Jesus will.
@-detectivealec8937
@-detectivealec8937 4 жыл бұрын
Thanks from 2020 lol, guess I'm starting late with programming
@coding-with-dave
@coding-with-dave 4 жыл бұрын
It's never too late to learn a superpower like programming :) Good luck.
@-detectivealec8937
@-detectivealec8937 3 жыл бұрын
@@coding-with-dave truth! I just got my first job as a back end developer. Started from scratch 6 months ago. Thanks again!
@coding-with-dave
@coding-with-dave 3 жыл бұрын
@@-detectivealec8937 Heck yeah! Nice job working hard and staying focused. Congrats.
@fariarana4599
@fariarana4599 4 жыл бұрын
whaft enviriomen iddid u use fir this vid
@coding-with-dave
@coding-with-dave 4 жыл бұрын
codepen.io
@charlesabinaar6563
@charlesabinaar6563 2 жыл бұрын
Im very new to JS, will this also work if not why not? multiply(prompt("Enter a number:"),("add" + "multiply"));
@coding-with-dave
@coding-with-dave 2 жыл бұрын
This will not work. The multiply function takes two parameters: n1 and n2, which both need to be numbers. The function call that you shared does pass in a number as the first parameters, n1, so long as they type in a number. The second parameter that you're passing in is not a number, it's a String instead. "add" is a String and "multiply" is a String. So your function call actually looks like this: multiply(prompt("Enter a number: "), "addmultiply")
@greenamogus
@greenamogus 2 жыл бұрын
I pray that you take this susbscription as a token of my gratitude!!!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Much appreciated. Thanks for the sub.
@flamablegas6308
@flamablegas6308 3 жыл бұрын
Summary: return means it'll take something and allow u to return that something later on
@coding-with-dave
@coding-with-dave 3 жыл бұрын
I would say that's sometimes correct. Functions that return a value don't have to "take something" or "pass in" any parameters. For instance, the function takes in a number but returns the value of true or false. It could also not pass in any value and return something. function isLarge(num) { if (num > 100) return true; else return false; } var number = prompt("Enter a number"); console.log(isLarge(number));
@venkatramanan266
@venkatramanan266 Жыл бұрын
thanks for explaining
@jayaditya5513
@jayaditya5513 2 жыл бұрын
Now i can sleep in peace.
@coding-with-dave
@coding-with-dave 2 жыл бұрын
I actually lol'ed. Thanks for that.
@fireball1433
@fireball1433 2 жыл бұрын
Thankss i was struggling to understand return
@coding-with-dave
@coding-with-dave 2 жыл бұрын
Glad it helped.
@latinstuff1
@latinstuff1 3 жыл бұрын
I am doing the udacity beginner introduction to JavaScript and it can get very fustrating sometimes since they don't seem to explain as well as this, thank you for clarifying this. the only thing that confuses me is how you named the variables outside the function body and they have the names number and another number, instead of N1 and N2. that still confuses me, I guess I have to rewatch this a few times to get it haha
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Yeah, that can easily be confusing. "number" and "anotherNumber" are variables that exist in the main part of the program (not in a function). After you pass them into a function they can be renamed, which is what I did. Usually, the parameters of a function have very generic names, like n1 and n2 in this case, so that it can be reused over and over with different values and in different situations. I tend to think of parameters as a list of the variables I can use in my function. So when I passed "number", which has a value of 4, into the function, that's like saying that "n1 = 4" inside the function. Hope that helps.
@latinstuff1
@latinstuff1 3 жыл бұрын
@@coding-with-dave it helps a lot thank you so much for this explanation ! I’m starting at Ironhack in March so I’m trying to prepare myself haha
@coding-with-dave
@coding-with-dave 3 жыл бұрын
@@latinstuff1 That's exciting. Good luck and have fun!
@latinstuff1
@latinstuff1 2 жыл бұрын
@@coding-with-dave :) thank you. This Monday is my first class. I’m ready !
@coding-with-dave
@coding-with-dave 2 жыл бұрын
@@latinstuff1 You got this! Have fun and give yourself some grace when things get tough. It's all part of learning.
@momakplayz7985
@momakplayz7985 3 жыл бұрын
Hi, i still dont know when to use the return function in my code :( Please help
@coding-with-dave
@coding-with-dave 3 жыл бұрын
If your main program needs a value, like a number, from your function, then return it. For example, you would like to make a program that determines the total cost (with taxes) of a purchase at a restaurant. In the first part of your program you'll be asking the user for the items they want to purchase. The next part of your program you'll determine the cost of those items. Then you decide to make a function that determines the total cost with tax based on your purchases. The function could pass in two parameters: the cost of the items so far and the tax rate. Your function will multiply those two parameters together and then add it to the cost to get the total cost. Now your main program doesn't know what the result of all the math you did in the function you just made. In order for it to know that you'll need to return that result back to the main program. So maybe you'll write something like: var total_cost = calculate_total_cost(cost, tax_rate) in your main program so that you can store what's being returned from your function in a variable called total_cost. Then the main program can do whatever it needs to do, like print a receipt. I hope that helps a bit. If you write your code like: var total_cost = 3; function calculate_total_cost(cost, tax_rate) { total_cost = 5; } calculate_total_cost(2,1); console.log(total_cost); Then using "return" from the function doesn't matter, since it will output 5, but a number of programming languages don't allow you write that code and have it work.
@abdullah3739
@abdullah3739 3 жыл бұрын
very easy to follow thanks
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Glad to hear that. Thanks.
@upsidegaming7134
@upsidegaming7134 2 жыл бұрын
at the start, I didn't see the variables at the top so I was so confused when number + anotherNumber equaled 7
@zelenimonter4901
@zelenimonter4901 Жыл бұрын
Do I need to convert prompt into a number?
@coding-with-dave
@coding-with-dave Жыл бұрын
Great question. I should have used either parseInt() or parseFloat() since I'm working with numbers.
@ldt8910
@ldt8910 3 жыл бұрын
Thank you so much!!!!!1
@carreraallen8327
@carreraallen8327 3 жыл бұрын
what compiler do you use bro
@coding-with-dave
@coding-with-dave 3 жыл бұрын
Codepen.io
@gabrielm909
@gabrielm909 3 ай бұрын
How does it know n1 is var number...?
@coding-with-dave
@coding-with-dave 3 ай бұрын
Great question. It doesn't. I should have forced it to be an integer by using `parseInt()` or `parseFloat()` for a non-whole number. So ultimately, it should have been `parseInt(input('Enter a number: "))`
@gabrielm909
@gabrielm909 3 ай бұрын
From what I’m learning it looks like (n1, n2) are the parameters and (number, anotherNumber) are the arguments.. 🤦🏻‍♂️ The whole parselnt thing is beyond my scope of what I think I know right now lol..
@mainstagesoundableton6213
@mainstagesoundableton6213 2 жыл бұрын
Awesome, thanks !
@coding-with-dave
@coding-with-dave 2 жыл бұрын
You bet. Glad it helped.
@kyleklaiber2225
@kyleklaiber2225 2 жыл бұрын
Nice! Thank you!!
@coding-with-dave
@coding-with-dave 2 жыл бұрын
For sure!
@SO-fb4ef
@SO-fb4ef 3 жыл бұрын
So return DOESN'T actually return anything, not by the definition of the word 'return'. Nothing is being returned to where it came from, it is being sent ONE WAY. It appears that 'return' is ACTUALLY more like an assignment operator. 'return' is like an = operator. The = operator's asociativity is 'right to left', but the 'return' operator's asociativity is different, it is 'right to inside the function name'? It is like an = operator which can REMOTELY associate? Am I right? so what is inside the Parameters is unassigned UNDEFINED value, ready to be defined - and what is after the word 'return' is assigned DEFINED value? What is the purpose of the code before the word 'return' then? and the code which comes after the word 'return'.does the code inside { } BEFORE the word 'return' gets ignored when said function is invoked??? Does it not get read or something? why write anything there if it does not get read?? What is the point of the code inside { } before the word 'return'? does the code before 'return', not return? does it turn into an origami paper crane and fly away? what happens to it? Please confirm this with me, I am still confused. I think 'return' is a terrible word for what happens. Am I correct?
@coding-with-dave
@coding-with-dave 3 жыл бұрын
It does return a value. It returns it to wherever the function was called. It's only able to assign the value in the function because it was returned. Not sure if that's the part that was confusing. Here is another example I made. (repl.it/@davidhust/return-function) It may not answer all of your questions so let me know if what else is unclear.
@SO-fb4ef
@SO-fb4ef 3 жыл бұрын
Ahh, thank you. I have not checked your link but I think this was the issue: I was under the impression that the decleration code is essentially copied and brought down for a split second, to be invoked in the position which the 'invoke function line' is written. But the truth is that the decleration code does not shift anywhere at all. What moves if the values in the invoke line parameters, these values are sent UP to the decleration, to assign to the undefined values in the decleration, and THEN are returned back to their original place and THIS is why the function is a reuseable piece of code - because without the return operator then the decleration would simply be updated, and defined by the invoke line of code. Am I right?
@SO-fb4ef
@SO-fb4ef 3 жыл бұрын
I would also like to say, despite still being confused after watching your video - your video was the clearest explanation I had seen yet, AND I am impressed with your fast reply to my comment. I will subscribe :)
@SO-fb4ef
@SO-fb4ef 3 жыл бұрын
Ahhh, so the return operator ASSIGNS, THEN RETURNS? Interesting
@coding-with-dave
@coding-with-dave 3 жыл бұрын
@@SO-fb4ef The return statement doesn't assign anything. Unless, we have a different definition of assign. It only replaces where the function was called with the value that is returned.
@theerana8042
@theerana8042 8 ай бұрын
I also implement in my VS code but its comes (NaN) was share any solution in the commentes .
@coding-with-dave
@coding-with-dave 7 ай бұрын
It might be because the prompt needs to be converted to an integer? Try breaking up line 13 into two separate lines like so: var userInput = parseInt(prompt("Enter a number: ")); var product = multiply(userInput, sum);
JavaScript Functions Crash Course
1:36:54
freeCodeCamp.org
Рет қаралды 199 М.
JavaScript FUNCTIONS are easy! 📞
12:14
Bro Code
Рет қаралды 52 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
#37 How to use JS return | JavaScript Full Tutorial
8:49
Dev Dreamer
Рет қаралды 26 М.
JavaScript Loops Made Easy
10:52
codeSTACKr
Рет қаралды 175 М.
The different types of JavaScript functions explained
14:47
Kevin Powell
Рет қаралды 46 М.
Basic JavaScript #11: return statement
4:16
Mehul - Codedamn
Рет қаралды 33 М.
Learn JavaScript OBJECTS in 7 minutes! 🧍
7:01
Bro Code
Рет қаралды 80 М.
What do JS functions really return? And why?
10:12
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 17 М.
Parameter vs Argument for Beginners | JavaScript Concepts Explained
7:52
#23 Function return and passing
5:09
Telusko
Рет қаралды 80 М.
JavaScript ES6 Arrow Functions Tutorial
9:32
Web Dev Simplified
Рет қаралды 847 М.
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН