{"id":3044,"date":"2020-09-02T08:51:00","date_gmt":"2020-09-02T08:51:00","guid":{"rendered":"http:\/\/the-codest.localhost\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/"},"modified":"2026-04-24T11:34:04","modified_gmt":"2026-04-24T11:34:04","slug":"osamstillt-og-einthrada-javascript-kynnast-atburdarhringnum","status":"publish","type":"post","link":"https:\/\/thecodest.co\/is\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/","title":{"rendered":"\u00d3samhli\u00f0a og ein\u00fer\u00e1\u00f0a JavaScript?"},"content":{"rendered":"<ul class=\"wp-block-list\">\n<li><strong>Keyrslut\u00edmi<\/strong><\/li>\n<\/ul>\n\n\n\n<p><a href=\"https:\/\/thecodest.co\/is\/blog\/hire-javascript-developer\/\">JavaScript<\/a> er t\u00falku\u00f0 forritunarm\u00e1l, ekki samansett. \u00deetta \u00fe\u00fd\u00f0ir a\u00f0 \u00fea\u00f0 \u00fearf t\u00falk sem umbreytir <a href=\"https:\/\/thecodest.co\/is\/blog\/hire-vue-js-developers\/\">JS<\/a> <a href=\"https:\/\/thecodest.co\/is\/dictionary\/what-is-code-refactoring\/\">k\u00f3\u00f0i<\/a> \u00ed v\u00e9lk\u00f3\u00f0a. \u00dea\u00f0 eru nokkrar tegundir t\u00falkana (svok\u00f6llu\u00f0 v\u00e9lar). Vins\u00e6lustu vafra v\u00e9larnar eru V8 (Chrome), Quantum (Firefox) og WebKit (Safari). A\u00f0 auki er V8 einnig nota\u00f0 \u00ed vins\u00e6lu forritunarumhverfi utan vafra, <a href=\"https:\/\/thecodest.co\/is\/blog\/find-your-node-js-expert-for-hire-today\/\">Node.js<\/a>.<\/p>\n\n\n\n<p>Hver v\u00e9l inniheldur minnishaug, k\u00f6llunarstafla, atbur\u00f0arhring, bi\u00f0r\u00f6\u00f0 k\u00f6llunarkalla og WebAPI me\u00f0 HTTP-bei\u00f0num, t\u00edmam\u00f3tum, atbur\u00f0um o.s.frv., allt framkv\u00e6mt \u00e1 sinn eigin h\u00e1tt til a\u00f0 hra\u00f0ari og \u00f6ruggari t\u00falkunar \u00e1 JS-k\u00f3\u00f0anum.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/app\/uploads\/2024\/05\/runtime-architecture.png\" alt=\"\u00der\u00f3un JavaScript\" title=\"\u00der\u00f3un JavaScript\"\/><\/figure>\n\n\n\n<p><em>Grunnuppbygging JS keyrslut\u00edmans. H\u00f6fundur: Alex Zlatkov<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Einstofna \u00fer\u00e1\u00f0ur<\/strong><\/h2>\n\n\n\n<p>Einst\u00e6\u00f0ra \u00fer\u00e1\u00f0a forritunarm\u00e1l er forritunarm\u00e1l me\u00f0 einum k\u00f6llunarpalla og einum minnishaug. \u00dea\u00f0 \u00fe\u00fd\u00f0ir a\u00f0 \u00fea\u00f0 keyrir a\u00f0eins eitt verkefni \u00ed einu.<\/p>\n\n\n\n<p>A&nbsp;<code>haugur<\/code>&nbsp;er samfelldur minnisv\u00e6\u00f0i sem \u00fathlutar sta\u00f0bundnu samhengi fyrir hvert keyrt fall.<\/p>\n\n\n\n<p>A&nbsp;<code>haugur<\/code>&nbsp;er mun st\u00e6rra sv\u00e6\u00f0i sem geymir allt sem \u00fathluta\u00f0 er d\u00fdnam\u00edskt.<\/p>\n\n\n\n<p>A&nbsp;<code>kallsr\u00f6\u00f0<\/code>&nbsp;er <a href=\"https:\/\/thecodest.co\/is\/blog\/app-data-collection-security-risks-value-and-types-explored\/\">g\u00f6gn<\/a> uppbygging sem \u00ed grundvallaratri\u00f0um skr\u00e1ir hvar vi\u00f0 erum \u00ed forritinu.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Kallsr\u00f6\u00f0<\/strong><\/h3>\n\n\n\n<p>Skrifum einfaldan k\u00f3\u00f0a og fylgjumst me\u00f0 \u00fev\u00ed sem gerist \u00e1 k\u00f6llunarr\u00f6\u00f0inni.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/app\/uploads\/2024\/05\/stack.gif\" alt=\"JavaScript hugb\u00fana\u00f0ar\u00fer\u00f3un\" title=\"JavaScript hugb\u00fana\u00f0ar\u00fer\u00f3un\"\/><\/figure>\n\n\n\n<p>Eins og sj\u00e1 m\u00e1 eru fallin b\u00e6tt vi\u00f0 k\u00f6llunarhringinn, keyr\u00f0 og s\u00ed\u00f0ar eytt. \u00deetta er svokalla\u00f0 LIFO-kerfi \u2013 s\u00ed\u00f0ast inn, fyrst \u00fat. Hver f\u00e6rsla \u00ed k\u00f6llunarhringnum kallast a&nbsp;<code>stafsrammi<\/code>.<\/p>\n\n\n\n<p>\u00deekking \u00e1 k\u00f6llunarr\u00f6\u00f0inni er gagnleg til a\u00f0 lesa villuspor. Almennt er n\u00e1kv\u00e6m \u00e1st\u00e6\u00f0a villunnar efst \u00ed fyrstu l\u00ednu, \u00fe\u00f3 a\u00f0 framkv\u00e6md k\u00f3\u00f0ans s\u00e9 fr\u00e1 ne\u00f0ri hluta upp.<\/p>\n\n\n\n<p>Stundum getur\u00f0u tekist \u00e1 vi\u00f0 algenga villu sem tilkynnt er um af\u00a0<code>H\u00e1marksst\u00e6r\u00f0 k\u00f6llunarr\u00f6\u00f0 hefur veri\u00f0 fari\u00f0 fram \u00far<\/code>. \u00dea\u00f0 er au\u00f0velt a\u00f0 f\u00e1 \u00feetta me\u00f0 endurk\u00f6llun:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">function foo() {\n    foo()\n}\nfoo()<\/code><\/pre>\n\n\n\n<p>og vafrinn e\u00f0a skelurinn okkar fr\u00fds. Hver vafrinn, jafnvel mismunandi \u00fatg\u00e1fur hans, hefur mismunandi h\u00e1marksst\u00e6r\u00f0 k\u00f6llunarstigs. \u00cd langflestum tilfellum duga \u00fe\u00e6r og \u00e1 a\u00f0 leita vandam\u00e1lsins annars sta\u00f0ar.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>St\u00edfla\u00f0ur hringingastafli<\/strong><\/h3>\n\n\n\n<p>H\u00e9r er d\u00e6mi um a\u00f0 hindra JS-\u00fer\u00e1\u00f0inn. Reyndum a\u00f0 lesa a&nbsp;<code>f\u00f3\u00f3<\/code>&nbsp;skr\u00e1r og a&nbsp;<code>bar<\/code>&nbsp;a\u00f0 nota <a href=\"https:\/\/thecodest.co\/is\/dictionary\/what-is-node-js-used-for\/\">Kn\u00fatur<\/a>.js samstillt fall&nbsp;<code>lestuSkr\u00e1Samstillt<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/app\/uploads\/2024\/05\/blocking.gif\" alt=\"JavaScript k\u00f3\u00f0i\" title=\"JavaScript k\u00f3\u00f0i\"\/><\/figure>\n\n\n\n<p>\u00deetta er hringr\u00e1sargif. Eins og \u00fe\u00fa s\u00e9r\u00f0, b\u00ed\u00f0ur JavaScript-v\u00e9lin eftir fyrstu k\u00f6lluninni.&nbsp;<code>lestuSkr\u00e1Samstillt<\/code>&nbsp;er loki\u00f0. En \u00feetta mun ekki gerast vegna \u00feess a\u00f0 \u00fea\u00f0 er ekkert&nbsp;<code>f\u00f3\u00f3<\/code>&nbsp;skr\u00e1, svo a\u00f0 \u00f6nnur falli\u00f0 ver\u00f0ur aldrei kalla\u00f0.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u00d3samstillt atferli<\/strong><\/h2>\n\n\n\n<p>Hins vegar getur JS einnig veri\u00f0 \u00f3blokkandi og haga\u00f0 s\u00e9r eins og \u00fea\u00f0 v\u00e6ri fj\u00f6l\u00fer\u00e1\u00f0a. \u00dea\u00f0 \u00fe\u00fd\u00f0ir a\u00f0 \u00fea\u00f0 b\u00ed\u00f0ur ekki eftir svari vi\u00f0 <a href=\"https:\/\/thecodest.co\/is\/blog\/compare-staff-augmentation-firms-that-excel-in-api-team-staffing-for-financial-technology-projects\/\">forritaskil<\/a> s\u00edmt\u00f6l, I\/O-atbur\u00f0ir o.s.frv., og geta haldi\u00f0 \u00e1fram k\u00f3\u00f0akeyrslu. \u00deetta er m\u00f6gulegt \u00fe\u00f6kk s\u00e9 JS-v\u00e9lum sem nota (undir v\u00e9larh\u00fasinu) raunveruleg fj\u00f6l\u00fer\u00e1\u00f0a forritunarm\u00e1l, eins og C++ (Chrome) e\u00f0a Rust (Firefox). \u00de\u00e6r bj\u00f3\u00f0a upp \u00e1 <a href=\"https:\/\/thecodest.co\/is\/blog\/why-us-companies-are-opting-for-polish-developers\/\">okkur<\/a> me\u00f0 <a href=\"https:\/\/thecodest.co\/is\/blog\/find-your-ideal-stack-for-web-development\/\">Vefur<\/a> API undir v\u00e9larhl\u00edfum vafra e\u00f0a t.d. I\/O API undir Node.js.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/app\/uploads\/2024\/05\/callback-queue.gif\" alt=\"JavaScript forritunarm\u00e1l\" title=\"JavaScript forritunarm\u00e1l\"\/><\/figure>\n\n\n\n<p>\u00cd GIF-inu h\u00e9r a\u00f0 ofan sj\u00e1um vi\u00f0 a\u00f0 fyrsta falli\u00f0 er sett \u00e1 k\u00f6llunarhringinn og&nbsp;<code>H\u00e6<\/code>&nbsp;er strax framkv\u00e6mt \u00ed kons\u00f3linni.<\/p>\n\n\n\n<p>S\u00ed\u00f0an k\u00f6llum vi\u00f0&nbsp;<code>setTimeout<\/code>&nbsp;Fall sem vafrinn veitir \u00ed gegnum WebAPI. \u00dea\u00f0 fer \u00ed k\u00f6llunarhringinn og asynkr\u00f3na afturk\u00f6llun hans.&nbsp;<code>f\u00f3\u00f3<\/code>&nbsp;Funk\u00edan fer \u00ed bi\u00f0r\u00f6\u00f0 WebApi, \u00fear sem h\u00fan b\u00ed\u00f0ur eftir k\u00f6lluninni sem \u00e1 a\u00f0 eiga s\u00e9r sta\u00f0 eftir 3 sek\u00fandur.<\/p>\n\n\n\n<p>\u00c1 me\u00f0an heldur forriti\u00f0 \u00e1fram k\u00f3\u00f0anum og vi\u00f0 sj\u00e1um&nbsp;<code>H\u00e6. \u00c9g er ekki blokka\u00f0ur.<\/code>&nbsp;\u00ed stj\u00f3rnbor\u00f0inu.<\/p>\n\n\n\n<p>Eftir a\u00f0 \u00fev\u00ed er kalla\u00f0 \u00e1 \u00fea\u00f0 fer hver a\u00f0ger\u00f0 \u00ed bi\u00f0r\u00f6\u00f0 WebAPI til&nbsp;<code>S\u00edmtalsr\u00f6\u00f0<\/code>. \u00dea\u00f0 er \u00fear sem fall b\u00ed\u00f0a \u00fear til k\u00f6llunarhringurinn er t\u00f3mur. \u00deegar \u00fea\u00f0 gerist eru \u00feau flutt \u00feanga\u00f0 eitt \u00ed einu.<\/p>\n\n\n\n<p>Svo, \u00feegar okkar&nbsp;<code>setTimeout<\/code>&nbsp;T\u00edminn l\u00fdkur ni\u00f0urtalningunni, okkar&nbsp;<code>f\u00f3\u00f3<\/code>&nbsp;fall fer \u00ed bi\u00f0r\u00f6\u00f0 k\u00f6llunara\u00f0fer\u00f0a, b\u00ed\u00f0ur \u00fear til k\u00f6llunarhringr\u00e1sin ver\u00f0ur tilt\u00e6k, fer \u00feanga\u00f0, er keyrt og vi\u00f0 sj\u00e1um&nbsp;<code>H\u00e6 fr\u00e1 \u00f3samstilltri callback<\/code>&nbsp;\u00ed stj\u00f3rnbor\u00f0inu.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Vi\u00f0bur\u00f0ahringr\u00e1s<\/strong><\/h3>\n\n\n\n<p>Spurningin er: Hvernig veit keyrslut\u00edminn a\u00f0 k\u00f6llunarhringurinn s\u00e9 t\u00f3mur og hvernig er atbur\u00f0urinn \u00ed callback-r\u00f6\u00f0inni kalla\u00f0ur? Kynntu \u00fe\u00e9r atbur\u00f0arhringinn. Hann er hluti af JavaScript-v\u00e9linni. \u00deessi ferill athugar st\u00f6\u00f0ugt hvort k\u00f6llunarhringurinn s\u00e9 t\u00f3mur og, ef svo er, fylgist me\u00f0 hvort atbur\u00f0ur s\u00e9 \u00ed callback-r\u00f6\u00f0inni sem b\u00ed\u00f0ur eftir a\u00f0 vera kalla\u00f0ur.<\/p>\n\n\n\n<p>\u00deetta er allt t\u00f6frinn \u00e1 bak vi\u00f0 tj\u00f6ldin!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>A\u00f0 draga saman kenninguna<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Samhli\u00f0a vinnsla og samhli\u00f0a framkv\u00e6md<\/strong><\/h3>\n\n\n\n<p><code>Samt\u00edmisvinna<\/code>&nbsp;merkir a\u00f0 framkv\u00e6ma m\u00f6rg verkefni \u00e1 sama t\u00edma en ekki samt\u00edmis. Til d\u00e6mis vinna tv\u00f6 verkefni \u00e1 yfirh\u00f6fu\u00f0num t\u00edmabilum.<\/p>\n\n\n\n<p><code>Samhli\u00f0a<\/code>&nbsp;merkir a\u00f0 framkv\u00e6ma tv\u00f6 e\u00f0a fleiri verkefni samt\u00edmis, t.d. a\u00f0 framkv\u00e6ma margar \u00fatreikningar \u00e1 sama t\u00edma.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u00der\u00e6\u00f0ir og ferlar<\/strong><\/h3>\n\n\n\n<p><code>\u00der\u00e6\u00f0ir<\/code>&nbsp;eru r\u00f6\u00f0 k\u00f3\u00f0akeyrslna sem h\u00e6gt er a\u00f0 keyra \u00f3h\u00e1\u00f0 hvorri annarri.<\/p>\n\n\n\n<p><code>Ferli<\/code>&nbsp;er d\u00e6mi um keyrandi forrit. Forrit getur haft marga ferla.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Samskeytis- og \u00f3samkeytis<\/strong><\/h3>\n\n\n\n<p>\u00cd&nbsp;<code>samstilltur<\/code>&nbsp;\u00cd forritun eru verkefni keyr\u00f0 eitt \u00e1 eftir \u00f6\u00f0ru. Hvert verkefni b\u00ed\u00f0ur eftir a\u00f0 fyrri verkefni lj\u00faki og er keyrt a\u00f0eins \u00fe\u00e1.<\/p>\n\n\n\n<p>\u00cd&nbsp;<code>\u00f3samstilltur<\/code>&nbsp;\u00cd forritun, \u00feegar eitt verkefni er keyrt, getur\u00f0u skipt yfir \u00ed anna\u00f0 verkefni \u00e1n \u00feess a\u00f0 b\u00ed\u00f0a eftir a\u00f0 hi\u00f0 fyrra lj\u00faki.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Samskeytis- og \u00f3samstilltar a\u00f0ger\u00f0ir \u00ed ein\u00fer\u00e1\u00f0a- og fj\u00f6l\u00fer\u00e1\u00f0aumhverfi<\/strong><\/h3>\n\n\n\n<p><code>Sams\u00fdnt me\u00f0 einni \u00fer\u00e6\u00f0i<\/code>Verkefni eru keyr\u00f0 eitt \u00e1 eftir \u00f6\u00f0ru. Hvert verkefni b\u00ed\u00f0ur eftir a\u00f0 fyrra verkefni s\u00e9 keyrt.<\/p>\n\n\n\n<p><code>Samskeytislega me\u00f0 m\u00f6rgum \u00fer\u00e1\u00f0um<\/code>Verkefni eru keyr\u00f0 \u00ed mismunandi \u00fer\u00e1\u00f0um en b\u00ed\u00f0a eftir \u00f6\u00f0rum verkefnum sem eru \u00ed gangi \u00e1 \u00f6\u00f0rum \u00fer\u00e1\u00f0um.<\/p>\n\n\n\n<p><code>\u00d3samsett me\u00f0 einni \u00fer\u00e6\u00f0i<\/code>Verkefni hefjast handa vi\u00f0 a\u00f0 framkv\u00e6ma \u00e1n \u00feess a\u00f0 b\u00ed\u00f0a eftir a\u00f0 anna\u00f0 verkefni lj\u00faki. \u00c1 hverjum t\u00edma er a\u00f0eins eitt verkefni \u00ed gangi.<\/p>\n\n\n\n<p><code>\u00d3samsett me\u00f0 m\u00f6rgum \u00fer\u00e1\u00f0um<\/code>Verkefni eru keyr\u00f0 \u00ed mismunandi \u00fer\u00e1\u00f0um \u00e1n \u00feess a\u00f0 b\u00ed\u00f0a eftir a\u00f0 \u00f6nnur verkefni lj\u00faki og lj\u00faka keyrslu sinni sj\u00e1lfst\u00e6tt.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>JavaScript-flokkun<\/strong><\/h2>\n\n\n\n<p>Ef vi\u00f0 sko\u00f0um hvernig JavaScript-v\u00e9lar virka undir v\u00e9larhu\u00f0inni, getum vi\u00f0 flokka\u00f0 JavaScript sem \u00f3samhverft og ein\u00fer\u00e1\u00f0a t\u00falku\u00f0 forritunarm\u00e1l. Or\u00f0i\u00f0 \u201ct\u00falka\u00f0\u201d er mj\u00f6g mikilv\u00e6gt \u00fev\u00ed \u00fea\u00f0 \u00fe\u00fd\u00f0ir a\u00f0 m\u00e1li\u00f0 s\u00e9 alltaf h\u00e1\u00f0 keyrslut\u00edma og aldrei eins hratt og \u00fe\u00fd\u00f0il \u00fej\u00e1lpu\u00f0 forritunarm\u00e1l me\u00f0 innbygg\u00f0u fj\u00f6l\u00fer\u00e1\u00f0a vinnu.<\/p>\n\n\n\n<p>\u00dea\u00f0 er vert a\u00f0 taka fram a\u00f0 Node.js getur n\u00e1\u00f0 raunverulegu fj\u00f6l\u00fer\u00e1\u00f0a vinnslu, a\u00f0 \u00fev\u00ed gefnu a\u00f0 hver \u00fer\u00e1\u00f0ur s\u00e9 keyr\u00f0ur sem sj\u00e1lfst\u00e6\u00f0ur ferill. \u00dea\u00f0 eru til b\u00f3kas\u00f6fn fyrir \u00feetta, en Node.js hefur innbygg\u00f0a eiginleika sem kallast&nbsp;<a href=\"https:\/\/nodejs.org\/api\/worker_threads.html#worker_threads_worker_threads\">Verk\u00fer\u00e1\u00f0ur<\/a>.<\/p>\n\n\n\n<p>Allir GIF-ar af atbur\u00f0ahringnum koma fr\u00e1&nbsp;<a href=\"https:\/\/github.com\/latentflip\/loupe\">St\u00e6kkunargler<\/a>&nbsp;Forrit sem Philip Roberts bj\u00f3 til, \u00fear sem \u00fe\u00fa getur pr\u00f3fa\u00f0 \u00f3samstilltar a\u00f0st\u00e6\u00f0ur \u00fe\u00ednar.<\/p>\n\n\n\n<p><b>Lesa meira:<\/b><\/p>\n\n\n\n<p><a href=\"https:\/\/thecodest.co\/blog\/why-you-should-probably-use-typescript\">Af hverju \u00e6ttir \u00fe\u00fa (l\u00edklega) a\u00f0 nota TypeScript?<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/thecodest.co\/blog\/quality-first-5-easy-steps-to-lint-your-code-with-github-workflows-in-javascript-project\/\">G\u00e6\u00f0i fyrst! 5 einf\u00f6ld skref til a\u00f0 lint-a k\u00f3\u00f0ann \u00feinn me\u00f0 GitHub-vinnufl\u00e6\u00f0i \u00ed JavaScript-verkefninu<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/thecodest.co\/blog\/how-to-improve-vue-js-apps-some-practical-tips\/\">Hvernig m\u00e1 b\u00e6ta Vue.js-forrit? Nokkur hagn\u00fdt r\u00e1\u00f0<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>JavaScript er ein\u00fer\u00e1\u00f0a forritunarm\u00e1l og jafnframt \u00f3blokkandi, \u00f3samhverft og samhli\u00f0a. \u00cd \u00feessari grein ver\u00f0ur \u00fatsk\u00fdrt hvernig \u00fea\u00f0 gerist.<\/p>","protected":false},"author":2,"featured_media":3045,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-3044","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Asynchronous and Single-threaded JavaScript? - The Codest<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thecodest.co\/is\/blogg\/osamstillt-og-einthrada-javascript-kynnast-atburdarhringnum\/\" \/>\n<meta property=\"og:locale\" content=\"is_IS\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Asynchronous and Single-threaded JavaScript?\" \/>\n<meta property=\"og:description\" content=\"JavaScript is a single-threaded language and, at the same time, also non-blocking, asynchronous and concurrent. This article will explain to you how it happens.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thecodest.co\/is\/blogg\/osamstillt-og-einthrada-javascript-kynnast-atburdarhringnum\/\" \/>\n<meta property=\"og:site_name\" content=\"The Codest\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-02T08:51:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-24T11:34:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-16.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"thecodest\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"thecodest\" \/>\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:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/\"},\"author\":{\"name\":\"thecodest\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/person\\\/7e3fe41dfa4f4e41a7baad4c6e0d4f76\"},\"headline\":\"Asynchronous and Single-threaded JavaScript?\",\"datePublished\":\"2020-09-02T08:51:00+00:00\",\"dateModified\":\"2026-04-24T11:34:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/\"},\"wordCount\":1058,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/cover-image-16.jpg\",\"articleSection\":[\"Software Development\"],\"inLanguage\":\"is\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/\",\"url\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/\",\"name\":\"Asynchronous and Single-threaded JavaScript? - The Codest\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/cover-image-16.jpg\",\"datePublished\":\"2020-09-02T08:51:00+00:00\",\"dateModified\":\"2026-04-24T11:34:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/#breadcrumb\"},\"inLanguage\":\"is\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"is\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/#primaryimage\",\"url\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/cover-image-16.jpg\",\"contentUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/cover-image-16.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thecodest.co\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Asynchronous and Single-threaded JavaScript?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#website\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"name\":\"The Codest\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thecodest.co\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"is\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\",\"name\":\"The Codest\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"is\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/03\\\/thecodest-logo.svg\",\"contentUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/03\\\/thecodest-logo.svg\",\"width\":144,\"height\":36,\"caption\":\"The Codest\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/pl.linkedin.com\\\/company\\\/codest\",\"https:\\\/\\\/clutch.co\\\/profile\\\/codest\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/person\\\/7e3fe41dfa4f4e41a7baad4c6e0d4f76\",\"name\":\"thecodest\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"is\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"caption\":\"thecodest\"},\"url\":\"https:\\\/\\\/thecodest.co\\\/is\\\/author\\\/thecodest\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u00d3samstillt og ein\u00fer\u00e1\u00f0a JavaScript? - The Codest","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:\/\/thecodest.co\/is\/blogg\/osamstillt-og-einthrada-javascript-kynnast-atburdarhringnum\/","og_locale":"is_IS","og_type":"article","og_title":"Asynchronous and Single-threaded JavaScript?","og_description":"JavaScript is a single-threaded language and, at the same time, also non-blocking, asynchronous and concurrent. This article will explain to you how it happens.","og_url":"https:\/\/thecodest.co\/is\/blogg\/osamstillt-og-einthrada-javascript-kynnast-atburdarhringnum\/","og_site_name":"The Codest","article_published_time":"2020-09-02T08:51:00+00:00","article_modified_time":"2026-04-24T11:34:04+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-16.jpg","type":"image\/jpeg"}],"author":"thecodest","twitter_card":"summary_large_image","twitter_misc":{"Written by":"thecodest","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/#article","isPartOf":{"@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/"},"author":{"name":"thecodest","@id":"https:\/\/thecodest.co\/#\/schema\/person\/7e3fe41dfa4f4e41a7baad4c6e0d4f76"},"headline":"Asynchronous and Single-threaded JavaScript?","datePublished":"2020-09-02T08:51:00+00:00","dateModified":"2026-04-24T11:34:04+00:00","mainEntityOfPage":{"@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/"},"wordCount":1058,"commentCount":0,"publisher":{"@id":"https:\/\/thecodest.co\/#organization"},"image":{"@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-16.jpg","articleSection":["Software Development"],"inLanguage":"is","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/","url":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/","name":"\u00d3samstillt og ein\u00fer\u00e1\u00f0a JavaScript? - The Codest","isPartOf":{"@id":"https:\/\/thecodest.co\/#website"},"primaryImageOfPage":{"@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/#primaryimage"},"image":{"@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-16.jpg","datePublished":"2020-09-02T08:51:00+00:00","dateModified":"2026-04-24T11:34:04+00:00","breadcrumb":{"@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/#breadcrumb"},"inLanguage":"is","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/"]}]},{"@type":"ImageObject","inLanguage":"is","@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/#primaryimage","url":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-16.jpg","contentUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-16.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/thecodest.co\/blog\/asynchronous-and-single-threaded-javascript-meet-the-event-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thecodest.co\/"},{"@type":"ListItem","position":2,"name":"Asynchronous and Single-threaded JavaScript?"}]},{"@type":"WebSite","@id":"https:\/\/thecodest.co\/#website","url":"https:\/\/thecodest.co\/","name":"The Codest","description":"","publisher":{"@id":"https:\/\/thecodest.co\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thecodest.co\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"is"},{"@type":"Organization","@id":"https:\/\/thecodest.co\/#organization","name":"The Codest","url":"https:\/\/thecodest.co\/","logo":{"@type":"ImageObject","inLanguage":"is","@id":"https:\/\/thecodest.co\/#\/schema\/logo\/image\/","url":"https:\/\/thecodest.co\/app\/uploads\/2024\/03\/thecodest-logo.svg","contentUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/03\/thecodest-logo.svg","width":144,"height":36,"caption":"The Codest"},"image":{"@id":"https:\/\/thecodest.co\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/pl.linkedin.com\/company\/codest","https:\/\/clutch.co\/profile\/codest"]},{"@type":"Person","@id":"https:\/\/thecodest.co\/#\/schema\/person\/7e3fe41dfa4f4e41a7baad4c6e0d4f76","name":"thecodest","image":{"@type":"ImageObject","inLanguage":"is","@id":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","caption":"thecodest"},"url":"https:\/\/thecodest.co\/is\/author\/thecodest\/"}]}},"_links":{"self":[{"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/posts\/3044","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/comments?post=3044"}],"version-history":[{"count":6,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/posts\/3044\/revisions"}],"predecessor-version":[{"id":7721,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/posts\/3044\/revisions\/7721"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/media\/3045"}],"wp:attachment":[{"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/media?parent=3044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/categories?post=3044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecodest.co\/is\/wp-json\/wp\/v2\/tags?post=3044"}],"curies":[{"name":"vp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}