{"id":13621,"date":"2022-03-22T11:29:28","date_gmt":"2022-03-22T11:29:28","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=13621"},"modified":"2024-02-16T10:46:50","modified_gmt":"2024-02-16T10:46:50","slug":"callback-vs-promise-js","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=13621","title":{"rendered":"Callback vs. Promise (JS)"},"content":{"rendered":"<p>They are used to handle asynchronous (single-threaded) execution.<\/p>\n<hr>\n<p><strong>Callback<\/strong> (Old school)<br \/>\nA Callback is a function<br \/>\n&#8230; that gets injected into another function as an argument<br \/>\n&#8230; and executed from within that function for further operation.<\/p>\n<p><a href=\"http:\/\/www.max-sperling.bplaced.net\/?p=13566\">Example<\/a> (see XHR)<\/p>\n<hr>\n<p><strong>Promise<\/strong> (New School)<br \/>\nA Promise is an object<br \/>\n&#8230; that gets returned by an asynchronous function<br \/>\n&#8230; which represents the current state of the operation.<\/p>\n<p>Async\/Await &#8230; is just syntactic sugar to handle promises.<\/p>\n<p><a href=\"http:\/\/www.max-sperling.bplaced.net\/?p=13566\">Example<\/a> (see Fetch)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>They are used to handle asynchronous (single-threaded) execution. Callback (Old school) A Callback is a function &#8230; that gets injected<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[55],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/13621"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13621"}],"version-history":[{"count":1,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/13621\/revisions"}],"predecessor-version":[{"id":16828,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/13621\/revisions\/16828"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13621"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}