{"id":19634,"date":"2020-07-16T17:11:54","date_gmt":"2020-07-17T00:11:54","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19634"},"modified":"2023-12-01T03:55:24","modified_gmt":"2023-12-01T11:55:24","slug":"javascript-promise","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-promise\/","title":{"rendered":"How to Use JavaScript Promises"},"content":{"rendered":"\n<p>Asynchronous code used to be a pain to write in JavaScript. To write <a href=\"https:\/\/careerkarma.com\/blog\/javascript-async-await\/\">asynchronous operations<\/a> in your code, you would have to deal with multiple levels of callback functions. The more functions that you introduced into your code, the harder it was to read.<br><\/p>\n\n\n\n<p>In ES6, promises came to the rescue. Promises are a way to write asynchronous code efficiently in JavaScript.<br><\/p>\n\n\n\n<p>In this guide, we\u2019re going to talk about what promises are and how they work. We\u2019ll walk through an example of a promise to help you learn how to use them in your code. Let\u2019s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Promise?<\/h2>\n\n\n\n<p>A promise is an object that returns a response that you want to receive in the future.<br><\/p>\n\n\n\n<p>A good way to think about JavaScript promises is to compare them to how people make promises. When you make a promise, it is an assurance that you are going to do something at a future date. You are not going to do that thing now; you will do it at some point later on.<br><\/p>\n\n\n\n<p>A promise can exist in one of three states:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Pending: A promise has not yet been completed.<\/li><li>Rejected: A promise has failed to return a value.<\/li><li>Fulfilled: A promise has been completed.<\/li><\/ul>\n\n\n\n<p>This is similar to promises in real life. You can have a pending promise which you say you are going to carry out in the future. You can fulfill a promise. You can reject, or \u201cbreak\u201d a promise, and not follow through on what you have agreed to do.<br><\/p>\n\n\n\n<p>When you make a promise, it will be pending. The promise will exist in this state until a response is received and the promise is either fulfilled or rejected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Create a JavaScript Promise<\/h2>\n\n\n\n<p>We\u2019re going to start by creating a promise which returns a user\u2019s name. This function will return a user\u2019s name to our program after three seconds. This will help us see how promises are used to write asynchronous code.<br><\/p>\n\n\n\n<p>To create a promise, we need to create a Promise object:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>new Promise((resolve, reject) =&gt; { \n\t\/\/ Your code here\n});\n<\/pre><\/div>\n\n\n\n<p>Promises accept two arguments: a function that handles the success of the promise and a function that handles a failed promise. This means that our promise will return different values depending on its outcome.<br><\/p>\n\n\n\n<p>A promise should contain an \u201cif\u201d statement that determines whether a promise has executed successfully. If a promise has not executed successfully, it should return a rejected state promise:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>new Promise((resolve, reject) =&gt; { \n\tif (value is true) {\n\t\tresolve();\n\t} else {\n\t\treject();\n\t}\n});\n<\/pre><\/div>\n\n\n\n<p>Open a new JavaScript file and copy in the following code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>let returnName = new Promise((resolve, reject) =&gt; {\n\tlet name;\n\tsetTimeout(() =&gt; {\n\t\tname = &quot;Cinnamon&quot;;\n\n\t\tif (name === &quot;Cinnamon&quot;) {\n\t\t\tresolve(name);\n\t\t} else {\n\t\t\treject(&quot;This promise has failed.&quot;);\n\t\t}\n\t}, 3000);\n});\n<\/pre><\/div>\n\n\n\n<p>This code returns the name <code>Cinnamon<\/code> to our main program when we call the promise. This code takes three seconds to run, or 3,000 milliseconds. This means that when we call our promise it will be pending for three seconds. After the promise is settled, a resolved or rejected promise will be returned to our main program.<br><\/p>\n\n\n\n<p>If \u201cname\u201d is equal to \u201cCinnamon\u201d, our promise is resolved successfully; otherwise, our promise will be rejected. In this example, \u201cname\u201d is set to \u201cCinnamon\u201d. Because we have specified a name, our promise resolves itself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">then() and catch() with Promises<\/h2>\n\n\n\n<p>Our code does not execute yet. We have to call our promise object:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>returnName.then(data =&gt; {\n\tconsole.log(data);\n});\n<\/pre><\/div>\n\n\n\n<p>The <code>then()<\/code> keyword allows us to retrieve a response from our promise. It is called after the promise is resolved. In this example, we print out the contents of <code>data<\/code>, which is the response returned from our promise, to the console.<br><\/p>\n\n\n\n<p>Our code returns: Cinnamon.<br><\/p>\n\n\n\n<p><code>then()<\/code> only handles successful promises. What happens if our promise is rejected? That\u2019s where the <code>catch()<\/code> method comes in.<br><\/p>\n\n\n\n<p>You can state multiple <code>then() <\/code>statements inside a promise. This is called promise chaining. Let\u2019s use an example to illustrate how chaining works:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>returnName.then(data =&gt; {\n\tconsole.log(data);\n}).then(() =&gt; {\n\tconsole.log(&quot;This function is over!&quot;);\n<\/pre><\/div>\n\n\n\n<p>This code will return:<br><\/p>\n\n\n\n<p>Cinnamon<\/p>\n\n\n\n<p>This function is over.<br><\/p>\n\n\n\n<p>then() statements are executed in the order they are specified inside a promise constructor.<br><\/p>\n\n\n\n<p>The <code>catch() <\/code>method is attached to a promise like the <code>then() <\/code>method. Let\u2019s create a handler which manages a rejected promise for our name example:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>returnName.then(data =&gt; {\n\tconsole.log(data);\n}).catch(error =&gt; {\n\tconsole.log(error);\n});\n<\/pre><\/div>\n\n\n\n<p>We have tacked on a <code>catch() <\/code>statement after our <code>then() <\/code>statement. Notice that we use a semicolon (;) at the very end of our promise code. You should not specify a semicolon after the <code>then()<\/code> method if you are using <code>catch()<\/code>. This will tell JavaScript that then() and catch() are separate, and so an error will be returned in your code.<br><\/p>\n\n\n\n<p>If our promise is rejected, the contents of the catch() statement will run.<br><\/p>\n\n\n\n<p>Let\u2019s see what happens when we run our code:<br><\/p>\n\n\n\n<p>Cinnamon<br><\/p>\n\n\n\n<p>The value <code>Cinnamon<\/code> is returned because our promise resolves successfully. If the value of \u201cname\u201d was not \u201cCinnamon\u201d in our promise, an error would be returned:<br><\/p>\n\n\n\n<p>Uncaught (in promise) This promise has failed.<br><\/p>\n\n\n\n<p>We specified the error message: \u201cThis promise has failed.\u201d in our reject() function inside our promise.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">finally() with Promises<\/h2>\n\n\n\n<p>What happens if you want to execute a block of code after a promise has executed, irrespective of whether the promise succeeded or failed?<br><\/p>\n\n\n\n<p>That\u2019s where the <code>finally() <\/code>statement comes in handy. The <code>finally() <\/code>statement runs whether or not a promise is fulfilled or rejected. Let\u2019s update our promise call to use a finally statement:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>returnName.then(data =&gt; {\n\tconsole.log(data);\n}).catch(error =&gt; {\n\tconsole.log(error);\n}).finally(() =&gt; {\n\tconsole.log(&quot;The returnName promise has been executed.&quot;);\n});\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>Cinnamon<\/p>\n\n\n\n<p>The returnName promise has been executed.<br><\/p>\n\n\n\n<p>Our promise returns <code>Cinnamon<\/code> because it was successful. The contents of the <code>finally()<\/code> statement are then executed, which returns another message to our console.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>JavaScript promises allow you to write clean asynchronous code.&nbsp;<br><\/p>\n\n\n\n<p>In this guide, we have covered the fundamentals of promises. There is a lot more to promises than we have covered in this guide. The next step in your learning journey is to write a few promises in your own code.<br><\/p>\n\n\n\n<p>Here\u2019s a challenge: write a promise which makes a web request and returns its response. To do this, you will want to use the <a href=\"https:\/\/careerkarma.com\/blog\/javascript-fetch\/\">fetch()<\/a> API to make a request. This request should be enclosed within a promise. You should write code that handles the promise both if it succeeds or fails.<br><\/p>\n\n\n\n<p>If you want to go further, check out <a href=\"https:\/\/careerkarma.com\/blog\/javascript-async-await\/\">JavaScript async functions.<\/a> These can be used to write asynchronous code and are commonly used with Promises.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to start writing JavaScript promises like an expert!<br><\/p>\n","protected":false},"excerpt":{"rendered":"Asynchronous code used to be a pain to write in JavaScript. To write asynchronous operations in your code, you would have to deal with multiple levels of callback functions. The more functions that you introduced into your code, the harder it was to read. In ES6, promises came to the rescue. Promises are a way&hellip;","protected":false},"author":240,"featured_media":2620,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-19634","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Use JavaScript Promises | Career Karma<\/title>\n<meta name=\"description\" content=\"A promise is an object that will produce a value in the future. On Career Karma, learn how to use JavaScript promises.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-promise\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use JavaScript Promises\" \/>\n<meta property=\"og:description\" content=\"A promise is an object that will produce a value in the future. On Career Karma, learn how to use JavaScript promises.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-promise\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-17T00:11:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:55:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/irvan-smith-563895-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"How to Use JavaScript Promises\",\"datePublished\":\"2020-07-17T00:11:54+00:00\",\"dateModified\":\"2023-12-01T11:55:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/\"},\"wordCount\":1025,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/irvan-smith-563895-unsplash.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/\",\"name\":\"How to Use JavaScript Promises | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/irvan-smith-563895-unsplash.jpg\",\"datePublished\":\"2020-07-17T00:11:54+00:00\",\"dateModified\":\"2023-12-01T11:55:24+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"A promise is an object that will produce a value in the future. On Career Karma, learn how to use JavaScript promises.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/irvan-smith-563895-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/irvan-smith-563895-unsplash.jpg\",\"width\":1200,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-promise\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Use JavaScript Promises\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use JavaScript Promises | Career Karma","description":"A promise is an object that will produce a value in the future. On Career Karma, learn how to use JavaScript promises.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/javascript-promise\/","og_locale":"en_US","og_type":"article","og_title":"How to Use JavaScript Promises","og_description":"A promise is an object that will produce a value in the future. On Career Karma, learn how to use JavaScript promises.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-promise\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-17T00:11:54+00:00","article_modified_time":"2023-12-01T11:55:24+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/irvan-smith-563895-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"How to Use JavaScript Promises","datePublished":"2020-07-17T00:11:54+00:00","dateModified":"2023-12-01T11:55:24+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/"},"wordCount":1025,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/irvan-smith-563895-unsplash.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-promise\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/","url":"https:\/\/careerkarma.com\/blog\/javascript-promise\/","name":"How to Use JavaScript Promises | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/irvan-smith-563895-unsplash.jpg","datePublished":"2020-07-17T00:11:54+00:00","dateModified":"2023-12-01T11:55:24+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"A promise is an object that will produce a value in the future. On Career Karma, learn how to use JavaScript promises.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-promise\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/irvan-smith-563895-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/05\/irvan-smith-563895-unsplash.jpg","width":1200,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-promise\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"How to Use JavaScript Promises"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=19634"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19634\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/2620"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}