Are functions passed as parameters always callbacks? JavaScript -
if have code below, pass 2 functions parameters function sayhi, example of callback?
i notice there 2 ways of running these 'parameter functions': either below, call functions defined (as arguments), or alternatively call parameter in sayhi function. difference between callback , anonymous function?
function sayhi(name, testfortrue) { if (testfortrue == true) { console.log(name); } } sayhi(function() { return 'zach' }(), function() { return true; }()); another way same result, below. in case evaluating functions @ different time? there practical difference between two?
function sayhi(name, testfortrue) { if (testfortrue() == true) { console.log(name()); } } sayhi(function() { return 'zach' }, function() { return true; });
yes, functions passed parameters callbacks, if intention function called synchronously (c.f. array.prototype.map) rather asynchronously (c.f. window.settimeout).
in first code block aren't of course passing functions. have 2 immediately invoked function expressions, key part in context immediately invoked. function expressions called @ point appear in code , results of expressions passed sayhi.
Comments
Post a Comment