{"id":7978,"date":"2021-08-16T11:52:08","date_gmt":"2021-08-16T11:52:08","guid":{"rendered":"https:\/\/www.scmgalaxy.com\/tutorials\/?p=7978"},"modified":"2022-04-13T16:30:44","modified_gmt":"2022-04-13T16:30:44","slug":"how-do-you-handle-exceptions-in-javascript","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/","title":{"rendered":"How do you handle exceptions in JavaScript?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Exception<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An exception is a generalization of the concept of an error to include any unexpected condition encountered during execution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Exception Handling-<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>try<\/li><li>catch<\/li><li>finally<\/li><li>throw<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How does the Javascript callback function work?<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A callback function is a function (It can be any function Anonymous Function, Arrow Function) passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/4b5ca92cc0ead2542dda606d660f774e.js\"><\/script>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/dbc52c4aeaf527602582e68a15dfcb1b.js\"><\/script>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/5a1bc349107ba965e5a0ea974324d80b.js\"><\/script>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/a7fa5a554bd4df95ee87cf0f5bad3786.js\"><\/script>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/4dffab27870e811b327284976978cd5e.js\"><\/script>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/478ce075eb0baac6c52d536aee7a584c.js\"><\/script>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/2e068ae321c04c47e9c3e4a47418848e.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\">Synchronous &#8211; It waits for each operation to complete, after that it executes the next operation.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/vijaypk376\/71318fc08db2f5f80c686fcb8a520bbb.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\">Asynchronous &#8211; It never waits for each operation to complete, rather it executes all operations in the first GO only.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">map ( ) Method in JavaScript<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The map( ) method creates a new array with the results of calling a provided function on every element in the calling array.<br>the map calls a provided callback function once for each element in an array, in order, and returns a new array from the results.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax:-<br>map(callback(currentValue, index, array), thisArg);<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Exception An exception is a generalization of the concept of an error to include any unexpected condition encountered during execution. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[16],"tags":[6330,6329,5095,6331],"class_list":["post-7978","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-callback-function","tag-exception-handling","tag-javascript","tag-map-method"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How do you handle exceptions in JavaScript? - scmGalaxy<\/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:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How do you handle exceptions in JavaScript? - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"Exception An exception is a generalization of the concept of an error to include any unexpected condition encountered during execution. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-16T11:52:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-13T16:30:44+00:00\" \/>\n<meta name=\"author\" content=\"rajeshkumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rajeshkumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/\"},\"author\":{\"name\":\"rajeshkumar\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\"},\"headline\":\"How do you handle exceptions in JavaScript?\",\"datePublished\":\"2021-08-16T11:52:08+00:00\",\"dateModified\":\"2022-04-13T16:30:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/\"},\"wordCount\":171,\"commentCount\":0,\"keywords\":[\"callback function\",\"Exception Handling\",\"Javascript\",\"map ( ) Method\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/\",\"name\":\"How do you handle exceptions in JavaScript? - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-08-16T11:52:08+00:00\",\"dateModified\":\"2022-04-13T16:30:44+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/how-do-you-handle-exceptions-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How do you handle exceptions in JavaScript?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\",\"name\":\"rajeshkumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"caption\":\"rajeshkumar\"},\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/rajeshkumar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How do you handle exceptions in JavaScript? - scmGalaxy","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:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How do you handle exceptions in JavaScript? - scmGalaxy","og_description":"Exception An exception is a generalization of the concept of an error to include any unexpected condition encountered during execution. [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/","og_site_name":"scmGalaxy","article_published_time":"2021-08-16T11:52:08+00:00","article_modified_time":"2022-04-13T16:30:44+00:00","author":"rajeshkumar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rajeshkumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/"},"author":{"name":"rajeshkumar","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361"},"headline":"How do you handle exceptions in JavaScript?","datePublished":"2021-08-16T11:52:08+00:00","dateModified":"2022-04-13T16:30:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/"},"wordCount":171,"commentCount":0,"keywords":["callback function","Exception Handling","Javascript","map ( ) Method"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/","name":"How do you handle exceptions in JavaScript? - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-08-16T11:52:08+00:00","dateModified":"2022-04-13T16:30:44+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/how-do-you-handle-exceptions-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"How do you handle exceptions in JavaScript?"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361","name":"rajeshkumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","caption":"rajeshkumar"},"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/rajeshkumar\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/7978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=7978"}],"version-history":[{"count":1,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/7978\/revisions"}],"predecessor-version":[{"id":7980,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/7978\/revisions\/7980"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=7978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=7978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=7978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}