{"id":416919,"date":"2024-06-30T01:14:54","date_gmt":"2024-06-30T01:14:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=416919"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=416919","title":{"rendered":"<span>\u0412 JS-\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u00ab\u043f\u043e\u0431\u0435\u0436\u0434\u0430\u0435\u0442\u00bb \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 return<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\u0412\u043e\u0442 \u2014 JavaScript-\u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u041a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 <code>return<\/code>, \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u043d\u0435\u0439, \u00ab\u043f\u043e\u0431\u0435\u0434\u0438\u0442\u00bb \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438?<\/p>\n<pre><code class=\"javascript\">function test() { \u00a0\u00a0return 'one'; \u00a0\u00a0return 'two'; \u00a0\u00a0return 'three'; } <\/code><\/pre>\n<p>  \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432\u044b \u0441\u043a\u0430\u0436\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 <code>return<\/code>. \u0410 \u0432\u043e\u0442 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0443\u0431\u0435\u0434\u0438\u0442\u044c \u0432\u0430\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u00ab\u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u0435\u043c\u00bb \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f <code>return<\/code> \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439.<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/567154\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/wo\/xw\/pp\/woxwppn0iznd8vikamlu40x4de8.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/wo\/xw\/pp\/woxwppn0iznd8vikamlu40x4de8.jpeg\" data-blurred=\"true\"\/><\/a><\/p>\n<p>  \u0411\u0443\u0434\u044c\u0442\u0435 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u044b: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>'one'<\/code>. \u041d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0432\u044b\u0439 <code>return<\/code> \u043d\u0435 \u0434\u0430\u0451\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u00ab\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 <code>return<\/code>\u00bb \u2014 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c <code>return 'one'<\/code>, \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u0438 \u00ab\u043f\u043e\u0431\u0435\u0436\u0434\u0430\u0435\u0442\u00bb \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <code>return<\/code>. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044d\u0442\u043e \u2014 \u0438 \u0441\u0430\u043c\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u043e, \u0447\u0442\u043e \u044f \u0437\u0430\u044f\u0432\u0438\u043b \u0432\u044b\u0448\u0435, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c (\u044f, \u0433\u043e\u0432\u043e\u0440\u044f \u044d\u0442\u043e, \u0441 \u0441\u0430\u043c\u043e\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0432\u0438\u0434\u043e\u043c \u0441\u043a\u0440\u0435\u0449\u0438\u0432\u0430\u044e \u0440\u0443\u043a\u0438 \u043d\u0430 \u0433\u0440\u0443\u0434\u0438).<\/p>\n<p>  \u0417\u043d\u0430\u044e, \u0432 \u0432\u0430\u0448\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u043e\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u043c\u044b\u0441\u043b\u044c: \u00ab\u0414\u0430 \u0437\u0430\u0442\u043a\u043d\u0438\u0441\u044c \u0443\u0436\u0435!\u00bb. \u041d\u043e \u044f, \u0432\u0441\u0451 \u0436\u0435, \u043f\u0440\u043e\u0448\u0443 \u0432\u0430\u0441 \u0435\u0449\u0451 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u0442\u0435\u0440\u043f\u0435\u0442\u044c\u2026<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2><font color=\"#3AC1EF\">\u0411\u043b\u043e\u043a finally<\/font><\/h2>\n<p>  \u0411\u043b\u043e\u043a <code>finally<\/code> \u2014 \u044d\u0442\u043e \u0432\u0435\u0449\u044c:<\/p>\n<pre><code class=\"javascript\">function finallyTest() { \u00a0\u00a0try { \u00a0\u00a0\u00a0\u00a0console.log('one'); \u00a0\u00a0\u00a0\u00a0return 'three'; \u00a0\u00a0} catch (err) { \u00a0\u00a0\u00a0\u00a0console.log('error'); \u00a0\u00a0} finally { \u00a0\u00a0\u00a0\u00a0console.log('two'); \u00a0\u00a0} }  console.log(finallyTest()); console.log('four'); <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u043f\u043e\u043f\u0430\u0434\u0451\u0442 <code>'one'<\/code>, <code>'two'<\/code>, <code>'three'<\/code>, <code>'four'<\/code>. \u0411\u043b\u043e\u043a <code>finally<\/code> \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0431\u043b\u043e\u043a\u043e\u0432 <code>try<\/code>\/<code>catch<\/code> \u2014 \u0434\u0430\u0436\u0435 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <code>return<\/code>.<\/p>\n<p>  \u042f \u0434\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0432 JavaScript \u0431\u043b\u043e\u043a\u043e\u043c <code>finally<\/code>, \u0430 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b \u0435\u0433\u043e \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">async function someAsyncThing() { \u00a0\u00a0startSpinner();  \u00a0\u00a0try { \u00a0\u00a0\u00a0\u00a0await asyncWork(); \u00a0\u00a0} catch (err) { \u00a0\u00a0\u00a0\u00a0if (err.name === 'AbortError') return; \u00a0\u00a0\u00a0\u00a0showErrorUI(); \u00a0\u00a0} finally { \u00a0\u00a0\u00a0\u00a0stopSpinner(); \u00a0\u00a0} } <\/code><\/pre>\n<p>  \u041d\u043e, \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e <code>finally<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u0434\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u0432 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"javascript\">function manyHappyReturns() { \u00a0\u00a0try { \u00a0\u00a0\u00a0\u00a0return 'one'; \u00a0\u00a0} finally { \u00a0\u00a0\u00a0\u00a0try { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 'two'; \u00a0\u00a0\u00a0\u00a0} finally { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 'three'; \u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0} } <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0430 <code>manyHappyReturns()<\/code> \u0431\u0443\u0434\u0435\u0442 <code>'three'<\/code>.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>return<\/code> \u0432\u0441\u0435\u0433\u0434\u0430 \u00ab\u043f\u043e\u0431\u0435\u0436\u0434\u0430\u0435\u0442\u00bb \u0434\u0440\u0443\u0433\u0438\u0435. \u041d\u0435 \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0432 \u0442\u0435\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0431\u0435\u0437\u0443\u043c\u0438\u0435\u043c, \u0430 \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c. \u0418 \u0440\u0435\u0447\u044c \u0442\u0443\u0442 \u0438\u0434\u0451\u0442 \u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u00ab\u043f\u043e\u0431\u0435\u0434\u0435\u00bb, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b, \u043c\u044b \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f <code>return<\/code> \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0422\u0430\u043a, <code>return<\/code> \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u043a\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 <code>return<\/code> \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>return<\/code>. \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0438 \u0434\u043b\u044f Java, \u0438 \u0434\u043b\u044f Python. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044e <a href=\"https:\/\/twitter.com\/littledan\/status\/1407883941634359298\">\u0414\u0430\u043d\u0438\u044d\u043b\u044f \u0415\u0440\u0435\u043d\u0431\u0435\u0440\u0433\u0430<\/a> \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u043b \u043c\u043e\u0451 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u044d\u0442\u0443 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c <code>return<\/code>.<\/p>\n<p>  \u041f\u043e\u0431\u043e\u0447\u043d\u044b\u043c \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435\u043c \u044d\u0442\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 <code>return<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0432 \u0431\u043b\u043e\u043a\u0435 <code>finally<\/code> \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0447\u0438\u0441\u0442\u043a\u0435 \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u043d\u0435\u0435 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<pre><code class=\"javascript\">function catchThis() { \u00a0\u00a0try { \u00a0\u00a0\u00a0\u00a0throw Error('boom'); \u00a0\u00a0} finally { \u00a0\u00a0\u00a0\u00a0return 'phew'; \u00a0\u00a0} } <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0430 <code>catchThis()<\/code> \u0431\u0443\u0434\u0435\u0442 <code>'phew'<\/code>.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d\u041a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435?<\/font><\/h3>\n<p>  \u041f\u043e\u043b\u0430\u0433\u0430\u044e, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0443 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 <code>return<\/code> \u043d\u0435\u0442. \u0421\u043f\u0430\u0441\u0438\u0431\u043e, \u0447\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430! \u0418 \u0435\u0449\u0451 \u2014 \u043f\u0440\u043e\u0448\u0443 \u0432\u0430\u0441 \u2014 \u043d\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u0445.<\/p>\n<h2><font color=\"#3AC1EF\">\u0411\u043e\u043d\u0443\u0441: \u043f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043e \u043f\u0440\u043e\u043c\u0438\u0441\u0430\u0445<\/font><\/h2>\n<p>  \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u044b\u0448\u0435 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u043d\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043f\u0440\u043e\u043c\u0438\u0441\u044b). \u041d\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <code>promise.finally()<\/code> \u0432\u0435\u0434\u0451\u0442 \u0441\u0435\u0431\u044f \u0438\u043d\u0430\u0447\u0435.<\/p>\n<pre><code class=\"javascript\">const promise = Promise.resolve('one').finally(() => 'two'); <\/code><\/pre>\n<p>  \u0422\u0443\u0442 <code>promise<\/code> \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>'one'<\/code>. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u044d\u0442\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u043c\u0438\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432 \u043d\u0435\u043a\u043e\u0435\u0433\u043e \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u0430, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u043e, \u0447\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u043b\u0431\u044d\u043a (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0441\u0430\u043c \u043f\u0440\u043e\u043c\u0438\u0441) \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432 <code>return undefined<\/code>, \u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>return<\/code>. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 <code>promise.finally()<\/code> \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043d\u044b\u0439 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0430 <code>finally<\/code>, \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0433\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0434\u0430, <code>promise.finally()<\/code> \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u043c\u0438\u0441 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d:<\/p>\n<pre><code class=\"javascript\">const wait = (ms) => new Promise((r) => setTimeout(() => r(), ms));  const promise = Promise.resolve('one').finally(async () => { \u00a0\u00a0await wait(2000); \u00a0\u00a0return 'two'; }); <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <code>promise<\/code>, \u0432\u0441\u0451 \u0442\u0430\u043a \u0436\u0435, \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>'one'<\/code>, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e \u0443 \u043d\u0435\u0433\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u0445\u043e\u0434\u0438\u0442 \u0434\u0432\u0435 \u0441\u0435\u043a\u0443\u043d\u0434\u044b.<\/p>\n<p>  \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0430\u043c \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e return, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f?<\/p>\n<p>  <a href=\"http:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=perevod&amp;utm_content=v_js-funkciyax_%C2%ABpobezhdaet%C2%BB_poslednij_operator_return\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ou\/g5\/kh\/oug5kh6sjydt9llengsiebnp40w.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ou\/g5\/kh\/oug5kh6sjydt9llengsiebnp40w.png\"\/><\/a><\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/567154\/\"> https:\/\/habr.com\/ru\/articles\/567154\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\u0412\u043e\u0442 \u2014 JavaScript-\u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u041a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 <code>return<\/code>, \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u043d\u0435\u0439, \u00ab\u043f\u043e\u0431\u0435\u0434\u0438\u0442\u00bb \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438?<\/p>\n<pre><code class=\"javascript\">function test() { \u00a0\u00a0return 'one'; \u00a0\u00a0return 'two'; \u00a0\u00a0return 'three'; } <\/code><\/pre>\n<p>  \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432\u044b \u0441\u043a\u0430\u0436\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 <code>return<\/code>. \u0410 \u0432\u043e\u0442 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0443\u0431\u0435\u0434\u0438\u0442\u044c \u0432\u0430\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u00ab\u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u0435\u043c\u00bb \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f <code>return<\/code> \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439.<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/567154\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/wo\/xw\/pp\/woxwppn0iznd8vikamlu40x4de8.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/wo\/xw\/pp\/woxwppn0iznd8vikamlu40x4de8.jpeg\" data-blurred=\"true\"\/><\/a><\/p>\n<p>  \u0411\u0443\u0434\u044c\u0442\u0435 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u044b: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>'one'<\/code>. \u041d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0432\u044b\u0439 <code>return<\/code> \u043d\u0435 \u0434\u0430\u0451\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u00ab\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 <code>return<\/code>\u00bb \u2014 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c <code>return 'one'<\/code>, \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u0438 \u00ab\u043f\u043e\u0431\u0435\u0436\u0434\u0430\u0435\u0442\u00bb \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <code>return<\/code>. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044d\u0442\u043e \u2014 \u0438 \u0441\u0430\u043c\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u043e, \u0447\u0442\u043e \u044f \u0437\u0430\u044f\u0432\u0438\u043b \u0432\u044b\u0448\u0435, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c (\u044f, \u0433\u043e\u0432\u043e\u0440\u044f \u044d\u0442\u043e, \u0441 \u0441\u0430\u043c\u043e\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u0432\u0438\u0434\u043e\u043c \u0441\u043a\u0440\u0435\u0449\u0438\u0432\u0430\u044e \u0440\u0443\u043a\u0438 \u043d\u0430 \u0433\u0440\u0443\u0434\u0438).<\/p>\n<p>  \u0417\u043d\u0430\u044e, \u0432 \u0432\u0430\u0448\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u043e\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u043c\u044b\u0441\u043b\u044c: \u00ab\u0414\u0430 \u0437\u0430\u0442\u043a\u043d\u0438\u0441\u044c \u0443\u0436\u0435!\u00bb. \u041d\u043e \u044f, \u0432\u0441\u0451 \u0436\u0435, \u043f\u0440\u043e\u0448\u0443 \u0432\u0430\u0441 \u0435\u0449\u0451 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u0442\u0435\u0440\u043f\u0435\u0442\u044c\u2026  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-416919","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/416919","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=416919"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/416919\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=416919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=416919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=416919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}