{"id":24473,"date":"2020-10-19T09:51:53","date_gmt":"2020-10-19T16:51:53","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=24473"},"modified":"2020-10-19T09:51:56","modified_gmt":"2020-10-19T16:51:56","slug":"javascript-sleep-alternatives","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/","title":{"rendered":"JavaScript Sleep Method Doesn\u2019t Exist: What to Use Instead"},"content":{"rendered":"\n<p>If you\u2019re an engineer or developer coming from different programming languages, you might have used a native method called <code>sleep()<\/code> to stall or pause a method from executing. JavaScript doesn\u2019t have such a native method.\u00a0<br><\/p>\n\n\n\n<p>In this article, we will talk about two different ways we can use JavaScript to simulate a sleep function: Promises and async\/await functions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to Asynchronous Functions<\/h2>\n\n\n\n<p>We shouldn\u2019t talk about Promises or async\/await functions in JavaScript without first mentioning the <code>setTimeout()<\/code> method briefly. This method will show why Promises are needed in JavaScript.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JavaScript is Single-Threaded<\/h3>\n\n\n\n<p>When we say JavaScript is a single-threaded language, what we mean is JavaScript only has one call stack and one memory heap. At a high level, this means JavaScript reads code, one line at a time, in order, and must execute a piece of code before moving to the next line. This makes JavaScript synchronous by nature. At times, we need a work around, to make our code asynchronous.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Synchronous Code vs Asynchronous Code<\/h4>\n\n\n\n<p>Take a look at this example.\u00a0<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/\/synchronous\nconsole.log(&quot;This will print first&quot;)\nconsole.log(&quot;This will print second&quot;)\nconsole.log(&quot;This will print third&quot;);<\/pre><\/div>\n\n\n\n<p>Pretty straightforward, right? Each of the console.logs will print in succession because JavaScript executes them in succession.&nbsp;<br><\/p>\n\n\n\n<p>Let\u2019s say we want line two to print before line three? How can we essentially print that <code>console.log<\/code> out of turn? We can do that with <code>setTimeout()<\/code>:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/\/setTimeout\nconsole.log(&quot;This will print first&quot;)\n \nsetTimeout(() =&gt; {\nconsole.log(&quot;This will print third&quot;)\n}, 1000);\n \nconsole.log(&quot;This will print second&quot;);<\/pre><\/div>\n\n\n\n<p><code>setTimeout()<\/code> allows us to execute a JavaScript function without blocking the thread so other code can run. The first argument is the callback function that runs after a set amount of time (the second argument). The second argument is represented in a number of milliseconds.<br><\/p>\n\n\n\n<p>This <code>setTimeout()<\/code> method mimics the sleep method that\u2019s native in other languages by:<br><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Setting a timer in the background when the JavaScript engine executes the <code>setTimeout()<\/code> function<\/li><li>Continuing to run other code as the timer does its countdown<\/li><li>Executing the callback function in <code>setTimeout()<\/code> when the timer reaches zero.<\/li><\/ol>\n\n\n\n<p>Understanding how <code>setTimeout()<\/code> works is crucial to being able to understand how Promises and async\/await Functions work. We\u2019ll cover Promises next.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Promises<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Creating a Promise<\/h3>\n\n\n\n<p>Promises are a way to perform asynchronous logic. The Promise constructor takes in a callback function that has two parameters: resolve and reject. This callback function contains logic that, once finished, will invoke a resolve or reject function with a response passed in.<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>console.log(&quot;before promise&quot;)\nlet promise = new Promise((resolve, reject) =&gt; {\n   let resolvedFlag = false; \n\/\/this is just a flag so we can intentionally throw the response to test logic\n   console.log(&quot;first&quot;);\n   console.log(&quot;second&quot;)\n   console.log(&quot;third&quot;)\n   console.log(&quot;fourth&quot;);\n   resolvedFlag = true; \/\/flip resolved to true once all console logs are done\n   \n   if(resolvedFlag) { \/\/if resolved is true invoke the resolve function \t\n        \nresolve(&quot;Promise resolved&quot;);\nconsole.log(&quot;after promise&quot;);\n \n \n   } else { \/\/ else invoke the reject function with a new Error object with message\n     reject(new Error(&quot;Promise failed&quot;)); \n     console.log(&quot;after promise&quot;);\n   }\n });<\/pre><\/div>\n\n\n\n<p>The code snippet here demonstrates a simple promise. Promises can be in three states:&nbsp;<br><\/p>\n\n\n\n<p>\t<strong>pending<\/strong> &#8211; Neither resolved or rejected \u2013 this is the initial state of the promise<\/p>\n\n\n\n<p><strong>resolved<\/strong> &#8211;&nbsp; Successful execution<\/p>\n\n\n\n<p>\t<strong>rejected<\/strong> &#8211;&nbsp; Error in execution<br><\/p>\n\n\n\n<p>Try toggling the resolvedFlag from true to false in the code snippet above to demonstrate the resolution of a resolved promise and a rejected promise.&nbsp;<br><\/p>\n\n\n\n<p>The main thing to remember is this Promise contains a function that pauses execution of the script until the Promise is resolved or rejected. Then the script resumes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using a Promise Response<\/h3>\n\n\n\n<p>When we initiate an instance of a Promise, we use <code>then()<\/code> and <code>catch()<\/code> to lay out the logic we want to use after we have received a response from the returned Promise. This is laid out as one statement \u2013 a high level overview looks like:<br><\/p>\n\n\n\n<p><strong>promise.then(func).catch(func);<\/strong><br><\/p>\n\n\n\n<p>In the parentheses that invokes the then and catch methods is an anonymous function that has the response passed in as a parameter.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>promise \/\/ the promise we created above in prev code snippet.\n   .then(response =&gt; { \/\/ hits here if successful response\n\/\/ the logic that happens on successful response\n     console.log(response); \n     console.log(&quot;after promise&quot;);\n   })\n   .catch(error =&gt; { \/\/ catches any errors here.\n\/\/ the logic that happens on error response\n     console.log(error.message);\n     console.log(&quot;after promise&quot;);\n   })<\/pre><\/div>\n\n\n\n<p>Promises are often used when making a call to a database or when making an HTTP request.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Async\/Await Functions<\/h2>\n\n\n\n<p>The final way we can simulate the <code>sleep()<\/code> method is by using async\/await functions. Essentially, these asynchronous functions are just another way of constructing the same logic that we would use in Promises, but with less code.<br><\/p>\n\n\n\n<p>The term <code>async<\/code> is placed before the <code>function<\/code> keyword in pre-ES6 functions, and before the parameters in ES6+ functions. Any logic you want done before moving on goes in this block of code.<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const firstFunction = () =&gt; { \/\/ logic that you want to have done asynchronously\n       let resolved = true;\n      \n       if(resolved) {\n         let respObj = { message: &quot;Resolved!&quot;};   \n         return respObj.message;\n       } else {\n         let errObj = { message: &quot;Error!&quot;};\n         return errObj.message;\n       }\n     }\n    \n     const asyncExample = async () =&gt; { \n\/\/ async keyword before where parameters would go\n       console.log(&quot;Calling function...&quot;);\n       let result = await firstFunction();\n\/\/ await goes before the invocation of the function that contains your logic.\n\/\/ won't go to the next line until the function is done. \n       console.log(result);\n       return result;\n     }\n    \n     asyncExample() \/\/ invokes the async\/await function<\/pre><\/div>\n\n\n\n<p>Using async\/await functions result in virtually the same asynchronous promise-based process but with less code.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this article we took a look at ways to mimic the <code>sleep()<\/code> function that is native to other programming languages. We used <code>setTimeout()<\/code> to demonstrate the concept of asynchronous JavaScript functions so that we could look at Promises and async\/await functions.<\/p>\n","protected":false},"excerpt":{"rendered":"If you\u2019re an engineer or developer coming from different programming languages, you might have used a native method called sleep() to stall or pause a method from executing. JavaScript doesn\u2019t have such a native method.\u00a0 In this article, we will talk about two different ways we can use JavaScript to simulate a sleep function: Promises&hellip;","protected":false},"author":77,"featured_media":24474,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-24473","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>JavaScript Sleep Alternatives | Career Karma<\/title>\n<meta name=\"description\" content=\"JavaScript doesn&#039;t have a native sleep() method like other languages do. Learn how to mimic sleep() in JavaScript with Promises and async\/await functions on Career Karma!\" \/>\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-sleep-alternatives\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Sleep Method Doesn\u2019t Exist: What to Use Instead\" \/>\n<meta property=\"og:description\" content=\"JavaScript doesn&#039;t have a native sleep() method like other languages do. Learn how to mimic sleep() in JavaScript with Promises and async\/await functions on Career Karma!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/\" \/>\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-10-19T16:51:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-19T16:51:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/10\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Christina Kopecky\" \/>\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=\"Christina Kopecky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/\"},\"author\":{\"name\":\"Christina Kopecky\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"headline\":\"JavaScript Sleep Method Doesn\u2019t Exist: What to Use Instead\",\"datePublished\":\"2020-10-19T16:51:53+00:00\",\"dateModified\":\"2020-10-19T16:51:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/\"},\"wordCount\":707,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/\",\"name\":\"JavaScript Sleep Alternatives | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg\",\"datePublished\":\"2020-10-19T16:51:53+00:00\",\"dateModified\":\"2020-10-19T16:51:56+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"description\":\"JavaScript doesn't have a native sleep() method like other languages do. Learn how to mimic sleep() in JavaScript with Promises and async\\\/await functions on Career Karma!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg\",\"width\":1020,\"height\":680,\"caption\":\"Russian blue cat napping\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-sleep-alternatives\\\/#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\":\"JavaScript Sleep Method Doesn\u2019t Exist: What to Use Instead\"}]},{\"@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\\\/ae0cdc4a5d198690d78482646894074e\",\"name\":\"Christina Kopecky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"caption\":\"Christina Kopecky\"},\"description\":\"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.\",\"sameAs\":[\"http:\\\/\\\/www.linkedin.com\\\/in\\\/cmvnk\"],\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/christina-kopecky\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript Sleep Alternatives | Career Karma","description":"JavaScript doesn't have a native sleep() method like other languages do. Learn how to mimic sleep() in JavaScript with Promises and async\/await functions on Career Karma!","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-sleep-alternatives\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Sleep Method Doesn\u2019t Exist: What to Use Instead","og_description":"JavaScript doesn't have a native sleep() method like other languages do. Learn how to mimic sleep() in JavaScript with Promises and async\/await functions on Career Karma!","og_url":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-10-19T16:51:53+00:00","article_modified_time":"2020-10-19T16:51:56+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/10\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg","type":"image\/jpeg"}],"author":"Christina Kopecky","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Christina Kopecky","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/"},"author":{"name":"Christina Kopecky","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"headline":"JavaScript Sleep Method Doesn\u2019t Exist: What to Use Instead","datePublished":"2020-10-19T16:51:53+00:00","dateModified":"2020-10-19T16:51:56+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/"},"wordCount":707,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/10\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/","url":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/","name":"JavaScript Sleep Alternatives | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/10\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg","datePublished":"2020-10-19T16:51:53+00:00","dateModified":"2020-10-19T16:51:56+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"description":"JavaScript doesn't have a native sleep() method like other languages do. Learn how to mimic sleep() in JavaScript with Promises and async\/await functions on Career Karma!","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/10\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/10\/alexander-possingham-CeWNEEsHPbA-unsplash.jpg","width":1020,"height":680,"caption":"Russian blue cat napping"},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-sleep-alternatives\/#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":"JavaScript Sleep Method Doesn\u2019t Exist: What to Use Instead"}]},{"@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\/ae0cdc4a5d198690d78482646894074e","name":"Christina Kopecky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","caption":"Christina Kopecky"},"description":"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.","sameAs":["http:\/\/www.linkedin.com\/in\/cmvnk"],"url":"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/24473","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\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=24473"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/24473\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/24474"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=24473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=24473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=24473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}