JavaScript for Developers 36 - Functions as arguments

preview_player
Показать описание

Thanks to functions being first class values, they can be passed as arguments to other functions. Let's see how that works!
Рекомендации по теме
Комментарии
Автор

Aha ! A big moment of understanding! Thanks for making some long-term confusion instantly get resolved.

GrayCo
Автор

Hey Koushik, wonderful explanation. Thanks for keeping it simple as usual.

dnyaneshtathode
Автор

Thank you! I was watching another tutorial and he did this, but didn't explain it, and I was left scratching my head. After a bit of Googling, I found this video and it helped me immensely! Thank you very much!! Hoping to see some Vue stuff from you in the near future! :)

foreverandadave
Автор

Hi, I just want to ask to ask about return statement, in the very first function if I provide a return statement then how can I access the return statement with the second function or pass a parameter for return statement.

anujkishor
Автор

There is no semicolon after the executor function.
It is defined to be as a value to a variable in the video.

Is it correct or JS interpreter just ignores it but it should be there?

hehythrjkljwqoi
Автор

hello there, can you show this with currying ?
I am struck in a middleware in redux project code where we are currying some action I am not getting an argument is being called as function/method.

export const loggerMiddleware = (store) => (next) => (action) => {
if (!action.type) {
return next(action);
}
console.log('type: ', action.type);
console.log('payload: ', action.payload);
console.log('currentState: ', store.getState());
next(action);//I am not getting this line
console.log('next state: ', store.getState());
};

mudassarnazar
Автор

Hi Koushik, i am not able to run javascript code from scratchpad. Should i download any plugins ? Please help me out. Thanks in advance.

indraalapati
Автор

hello, and thanks, just question, what if we have many argument like name, sruname and so on, and instead of console log return ?

bitoutsid-ahmed
Автор

I understand callbacks in C++ where you pass a 'pointer to a function' to another thread and wait for the callback result. This does not appear to be the same as a C++ callback. Maybe I'm not understanding the usecase in javascript, but this seems pointless. What problem does this technique solve?

fredjohnson
Автор

hi Kaushik, can you please explain me the output of this code


var f= function (){ console.log ("hello")};
var check = function(f)
{ console.log ("just checking " + f())};
check(f);
output is : hello
just checking undefined


Why there is undefined printed after "just checking"


thanks in anticitpation

sravanthihariprasad
Автор

How does line 7 or fn know to call line 1 (var f)?

davidcoronado
Автор

var f =function (name){
console.log("Hello "+name);
};

var executor = function(fn, name){
fn(name);
}
executor(f, "vinay");

From bottom line 3, why we have to give the argument name in that?

vinaygandhi
Автор

Why do functions get invoked as CALLBACK functions when stored in a variable? And yet when a normal function is stored in a variable it is not invoked. Where is the critical difference?

Martin
Автор

I was just trying some sample program to follow the tutorial and I came across the following behaviour.

var func = function(){
return 20;
};

function print(fn){
console.log(fn());
}

print(func);

When I use the function name as print, nothing gets printed to console, but print is not even a reserved word.
Can you please tell me why it behaves like this.

athrims
Автор

So what is the point of giving a _name_ in the function expression, if you cannot call it later on in the code?
Here is the example code with comments:

wvvwwwvvw
Автор

Would be great if you could have added the word "Call back" function concept in this.

anurangacse
Автор

hii! nice video! very informative!! can u please solve this doubt of mine.... in a function I have seen people put like function trial(obj){}. here, obj has some definite meaning or is like just some word.. pls reply asap

derenjeager
Автор

what is the advantage of this usage? Where can this be used fairly?

burakyigit
Автор

var f=function (){}; and function f(){}; seems to be the same thing.

LeeHongYee
Автор

Over simplified. In real world scenarios it's much more complicated.

RameenFallschirmjager
welcome to shbcf.ru