{"id":1717,"date":"2021-05-24T08:58:05","date_gmt":"2021-05-24T08:58:05","guid":{"rendered":"https:\/\/lvboard.infostore.in.ua\/?p=1717"},"modified":"2021-05-24T08:58:05","modified_gmt":"2021-05-24T08:58:05","slug":"7-%d0%b2%d0%be%d0%bf%d1%80%d0%be%d1%81%d0%be%d0%b2-%d0%bf%d1%80%d0%be-%d0%b7%d0%b0%d0%bc%d1%8b%d0%ba%d0%b0%d0%bd%d0%b8%d1%8f-%d0%b2-javascript","status":"publish","type":"post","link":"https:\/\/lvboard.infostore.in.ua\/?p=1717","title":{"rendered":"7 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0440\u043e \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f \u0432 JavaScript"},"content":{"rendered":"\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a JavaScript \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 (closure). \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e JavaScript \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e \u0432\u0430\u0441 \u0441\u043f\u0440\u043e\u0441\u044f\u0442 \u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u042f \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 7 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f\u043c \u0432 JavaScript.<\/p>\n\n\n\n<p>\u0412\u043e\u0437\u044c\u043c\u0438\u0442\u0435 \u043a\u0430\u0440\u0430\u043d\u0434\u0430\u0448, \u043b\u0438\u0441\u0442 \u0431\u0443\u043c\u0430\u0433\u0438 \u0438 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043d\u0435 \u0433\u043b\u044f\u0434\u044f \u043d\u0430 \u043e\u0442\u0432\u0435\u0442\u044b \u0438 \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044f \u043a\u043e\u0434. \u041f\u043e \u043c\u043e\u0438\u043c \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430\u043c, \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043e\u043a\u043e\u043b\u043e 30 \u043c\u0438\u043d\u0443\u0442.<\/p>\n\n\n\n<p>\u0420\u0430\u0437\u0432\u043b\u0435\u043a\u0430\u0439\u0442\u0435\u0441\u044c!<\/p>\n\n\n\n<p><em>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f \u043e \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0438, \u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0441 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0435\u0439&nbsp;<\/em><a href=\"https:\/\/dmitripavlutin.com\/simple-explanation-of-javascript-closures\/\"><em><u>A Simple Explanation of JavaScript Closures<\/u><\/em><\/a><em>&nbsp;(\u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f\u043c \u0432 JavaScript).<\/em><\/p>\n\n\n\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/strong><\/p>\n\n\n\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 1: \u0417\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0442 \u0442\u0432\u043e\u0438 \u0440\u0443\u043a\u0438&nbsp;<\/p>\n\n\n\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 2: \u0423\u0442\u0435\u0440\u044f\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/p>\n\n\n\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 3: \u041a\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0442\u043e<\/p>\n\n\n\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 4: \u0425\u0438\u0442\u0440\u043e\u0443\u043c\u043d\u043e\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435<\/p>\n\n\n\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 5: \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u043b\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435<\/p>\n\n\n\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 6: \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0438 (Restore encapsulation)<\/p>\n\n\n\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 7: \u0423\u043c\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435<\/p>\n\n\n\n<p>\u0420\u0435\u0437\u044e\u043c\u0435<\/p>\n\n\n\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441 1: \u0417\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0442 \u0442\u0432\u043e\u0438 \u0440\u0443\u043a\u0438&nbsp;<\/h3>\n\n\n\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:&nbsp;<code>clickHandler<\/code>,&nbsp;<code>immediate<\/code>, \u0438&nbsp;<code>delayReload<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let countClicks = 0;\nbutton.addEventListener('click', function clickHandler() {\n  countClicks++;\n});<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>const result = (function immediate(number) {\n  const message = `number is: ${number}`;\n  return message;\n})(100);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>setTimeout(function delayedReload() {\n  location.reload();\n}, 1000);<\/code><\/pre>\n\n\n\n<p>\u041a\u0430\u043a\u0438\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 3 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 (outer scope)?<\/p>\n\n\n\n<p><em>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442<\/em><\/p>\n\n\n\n<ol><li><code>clickHandler<\/code>&nbsp;&nbsp;<em>\u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f&nbsp;<\/em>\u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439&nbsp;<code>countClicks<\/code>&nbsp;\u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/li><li><code>immediate<\/code>&nbsp;<em>\u043d\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f<\/em>&nbsp;\u043d\u0438 \u043a \u043a\u0430\u043a\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/li><li><code>delayReload<\/code>&nbsp;<em>\u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f&nbsp;<\/em>\u043a \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439&nbsp;<code>location<\/code>&nbsp;&nbsp;\u0438\u0437 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 (\u0442\u0430\u043a \u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u043a\u0430\u043a \u043a\u0440\u0430\u0439\u043d\u044f\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 (outermost scope)).<\/li><\/ol>\n\n\n\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441 2: \u0423\u0442\u0435\u0440\u044f\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/h3>\n\n\n\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u043a\u043e\u0434\u0430 (code snippet):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(function immediateA(a) {\n  return (function immediateB(b) {\n    console.log(a); <em>\/\/ What is logged?<\/em>\n  })(1);\n})(0);<\/code><\/pre>\n\n\n\n<p><em>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442:<\/em><\/p>\n\n\n\n<p><code>0<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.&nbsp;<a href=\"https:\/\/jsitor.com\/_r8I1Do6L\"><u>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e<\/u><\/a>.<\/p>\n\n\n\n<p><code>immediateA<\/code>&nbsp;\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c&nbsp;<code>0<\/code>, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0440\u0430\u0432\u0435\u043d&nbsp;<code>0<\/code>.<\/p>\n\n\n\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<code>immediateB<\/code>, \u0431\u0443\u0434\u0443\u0447\u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<code>immediateA<\/code>, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e a \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438&nbsp;<code>immediateA<\/code>, \u0433\u0434\u0435&nbsp;<code>a<\/code>&nbsp;\u0440\u0430\u0432\u043d\u043e&nbsp;<code>0<\/code>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c,&nbsp;<code>console.log(a)<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 \u0436\u0443\u0440\u043d\u0430\u043b&nbsp;<code>0<\/code>.<\/p>\n\n\n\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441\u044b 3: \u041a\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0442\u043e<\/h3>\n\n\n\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u043a\u043e\u0434\u0430 (code snippet):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let count = 0;\n(function immediate() {\n  if (count === 0) {\n    let count = 1;\n    console.log(count); <em>\/\/ What is logged?<\/em>\n  }\n  console.log(count); <em>\/\/ What is logged?<\/em>\n})();<\/code><\/pre>\n\n\n\n<p><em>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442:<\/em><\/p>\n\n\n\n<p><code>1<\/code>&nbsp;\u0438&nbsp;<code>0<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.&nbsp;<a href=\"https:\/\/jsitor.com\/3c9T0QMAG\"><u>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e<\/u><\/a>.<\/p>\n\n\n\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435&nbsp;<code>let count = 0<\/code>&nbsp;\u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e&nbsp;<code>count<\/code>.<\/p>\n\n\n\n<p><code>immediate()<\/code>&nbsp;\u2014 \u044d\u0442\u043e \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e count \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u0412\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<code>immediate() count<\/code>&nbsp;\u0440\u0430\u0432\u043d\u0430&nbsp;<code>0<\/code>.<\/p>\n\n\n\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u0440\u0443\u0433\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430&nbsp;<code>let count = 1<\/code>&nbsp;\u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442&nbsp;<code>count<\/code>&nbsp;\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 count \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u0435\u0440\u0432\u0430\u044f&nbsp;&nbsp;<code>console.log(count)<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442&nbsp;<code>1<\/code>.<\/p>\n\n\n\n<p>\u0412\u0442\u043e\u0440\u0430\u044f&nbsp;<code>console.log(count)<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442&nbsp;<code>0<\/code>, \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f count \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n\n\n\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441 4: \u0425\u0438\u0442\u0440\u043e\u0443\u043c\u043d\u043e\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435<\/h3>\n\n\n\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u043a\u043e\u0434\u0430 (code snippet):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (var i = 0; i &lt; 3; i++) {\n  setTimeout(function log() {\n    console.log(i); <em>\/\/ What is logged?<\/em>\n  }, 1000);\n}<\/code><\/pre>\n\n\n\n<p><em>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442:<\/em><\/p>\n\n\n\n<p><code>3<\/code>,&nbsp;<code>3<\/code>,&nbsp;<code>3<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.&nbsp;<a href=\"https:\/\/jsitor.com\/8kit3zMOT\"><u>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e<\/u><\/a>.<\/p>\n\n\n\n<p>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 2 \u044d\u0442\u0430\u043f\u0430.<\/p>\n\n\n\n<p><strong>\u0424\u0430\u0437\u0430 1<\/strong><\/p>\n\n\n\n<ol><li><code>for()<\/code>&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e 3 \u0440\u0430\u0437\u0430. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<code>log()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e&nbsp;<code>i<\/code>.&nbsp;<code>setTimout()<\/code>&nbsp;\u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435&nbsp;<code>log()<\/code>&nbsp;\u0447\u0435\u0440\u0435\u0437 1000\u043c\u0441.<\/li><li>\u041a\u043e\u0433\u0434\u0430 \u0446\u0438\u043a\u043b&nbsp;<code>for()<\/code>&nbsp;\u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f&nbsp;<code>i<\/code>&nbsp;\u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 3.<\/li><\/ol>\n\n\n\n<p><strong>\u0424\u0430\u0437\u0430 2<\/strong><\/p>\n\n\n\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0444\u0430\u0437\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0441\u043b\u0435 1000 \u043c\u0441:<\/p>\n\n\n\n<ol><li><code>setTimeout()<\/code>&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<code>log()<\/code>.&nbsp;<code>log()<\/code>&nbsp;\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442&nbsp;<em>\u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/em>&nbsp;\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439&nbsp;<code>i<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0432\u043d\u043e 3, \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c 3.<\/li><\/ol>\n\n\n\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443&nbsp;<code>3<\/code>,&nbsp;<code>3<\/code>,&nbsp;<code>3<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.<\/p>\n\n\n\n<p><em>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430: \u043a\u0430\u043a \u0431\u044b \u0432\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438&nbsp;<\/em>0<em>,&nbsp;<\/em>1<em>,&nbsp;<\/em>2<em>&nbsp;? \u0417\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043d\u0438\u0436\u0435!<\/em><\/p>\n\n\n\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441 5: \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u043b\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435<\/h3>\n\n\n\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u043a\u043e\u0434\u0430 (code snippet):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function createIncrement() {\n  let count = 0;\n  function increment() { \n    count++;\n  }\n\n  let message = `Count is ${count}`;\n  function log() {\n    console.log(message);\n  }\n  \n  return &#91;increment, log];\n}\n\nconst &#91;increment, log] = createIncrement();\nincrement(); \nincrement(); \nincrement(); \nlog(); <em>\/\/ What is logged?<\/em><\/code><\/pre>\n\n\n\n<p><em>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442:<\/em><\/p>\n\n\n\n<p><code>'Count is 0'<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.&nbsp;<a href=\"https:\/\/jsitor.com\/W9goMvJt7\"><u>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e<\/u><\/a>.<\/p>\n\n\n\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<code>increment()<\/code>&nbsp;\u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c 3 \u0440\u0430\u0437\u0430, \u0432 \u0438\u0442\u043e\u0433\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044f&nbsp;<code>count<\/code>&nbsp;\u0434\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 3.<\/p>\n\n\n\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f&nbsp;<code>message<\/code>&nbsp;\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<code>createIncrement()<\/code>.&nbsp; \u0415\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435&nbsp;<code>'Count is 0'<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f&nbsp;<code>count<\/code>&nbsp;\u0431\u044b\u043b\u0430 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f&nbsp;<code>message<\/code>&nbsp; \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435&nbsp;<code>'Count is 0'<\/code>.<\/p>\n\n\n\n<p><code>\u0424\u0443\u043d\u043a\u0446\u0438\u044f log()<\/code>&nbsp;\u2014 \u044d\u0442\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e message \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438&nbsp;<code>createIncrement()<\/code>.&nbsp;<code>console.log(message)<\/code>&nbsp;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442&nbsp;<code>'Count is 0'<\/code>&nbsp;\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.<\/p>\n\n\n\n<p><em>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430: \u043a\u0430\u043a \u0431\u044b \u0432\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<\/em>log()<em>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0438\u043c\u0435\u044e\u0449\u0435\u0435 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435&nbsp;<\/em>count<em>? \u0417\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043d\u0438\u0436\u0435!<\/em><\/p>\n\n\n\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441 6: \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0438 (Restore encapsulation)<\/h3>\n\n\n\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<code>createStack()<\/code>&nbsp;\u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u0442\u0435\u043a\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function createStack() {\n  return {\n    items: &#91;],\n    push(item) {\n      this.items.push(item);\n    },\n    pop() {\n      return this.items.pop();\n    }\n  };\n}\n\nconst stack = createStack();\nstack.push(10);\nstack.push(5);\nstack.pop(); <em>\/\/ =&gt; 5<\/em>\n\nstack.items; <em>\/\/ =&gt; &#91;10]<\/em>\nstack.items = &#91;10, 100, 1000]; <em>\/\/ Encapsulation broken!<\/em><\/code><\/pre>\n\n\n\n<p>\u0421\u0442\u0435\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043d\u043e \u0441 \u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439. \u041b\u044e\u0431\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e&nbsp;<code>stack.items<\/code>&nbsp;\u043e\u0442\u043a\u0440\u044b\u0442\u043e.<\/p>\n\n\n\n<p>\u042d\u0442\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u0430\u044f \u0434\u0435\u0442\u0430\u043b\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044e \u0441\u0442\u0435\u043a\u0430: \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b&nbsp;<code>push()<\/code>&nbsp;\u0438&nbsp;<code>pop()<\/code>&nbsp;\u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c\u0438, \u0430&nbsp;<code>stack.items<\/code>&nbsp;\u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b.<\/p>\n\n\n\n<p>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0443\u0439\u0442\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0442\u0435\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f, \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0431\u044b\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0443&nbsp;<code>items<\/code>&nbsp;\u0432\u043d\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<code>createStack()<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function createStack() {\n  <em>\/\/ Write your code here...<\/em>\n}\n\nconst stack = createStack();\nstack.push(10);\nstack.push(5);\nstack.pop(); <em>\/\/ =&gt; 5<\/em>\n\nstack.items; <em>\/\/ =&gt; undefined<\/em><\/code><\/pre>\n\n\n\n<p><em>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442:<\/em><\/p>\n\n\n\n<p>\u0412\u043e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 (refactoring) \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<code>createStack()<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function createStack() {\n  const items = &#91;];\n  return {\n    push(item) {\n      items.push(item);\n    },\n    pop() {\n      return items.pop();\n    }\n  };\n}\n\nconst stack = createStack();\nstack.push(10);\nstack.push(5);\nstack.pop(); <em>\/\/ =&gt; 5<\/em>\n\nstack.items; <em>\/\/ =&gt; undefined<\/em><\/code><\/pre>\n\n\n\n<p>\u2192&nbsp;<a href=\"https:\/\/jsitor.com\/Am60z1bCI\"><u>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e<\/u><\/a><\/p>\n\n\n\n<p><code>items<\/code>&nbsp;\u0431\u044b\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438&nbsp;<code>createStack()<\/code>.<\/p>\n\n\n\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e, \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438&nbsp;<code>createStack()<\/code>, \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0443&nbsp;<code>items<\/code>&nbsp;\u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0433\u043e. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0430 \u0441\u0442\u0435\u043a \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d: \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b&nbsp;<code>push()<\/code>&nbsp;\u0438&nbsp;<code>pop()<\/code>&nbsp;\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c\u0438.<\/p>\n\n\n\n<p>\u041c\u0435\u0442\u043e\u0434\u044b&nbsp;<code>push()<\/code>&nbsp;\u0438&nbsp;<code>pop()<\/code>, \u0431\u0443\u0434\u0443\u0447\u0438 \u0437\u0430\u043c\u043a\u043d\u0443\u0442\u044b\u043c\u0438, \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e&nbsp;<code>items<\/code>&nbsp;\u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<code>createStack()<\/code>.<\/p>\n\n\n\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441 7: \u0423\u043c\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435<\/h3>\n\n\n\n<p>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<code>multiply()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442 2 \u0447\u0438\u0441\u043b\u0430:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function multiply(num1, num2) {\n  <em>\/\/ Write your code here...<\/em>\n}<\/code><\/pre>\n\n\n\n<p>\u0415\u0441\u043b\u0438&nbsp;<code>multiply(num1, numb2)<\/code>&nbsp;\u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0441 2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0442\u043e \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n\n\n\n<p>\u041d\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f 1 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442&nbsp;<code>const anotherFunc = multiply(numb1)<\/code>, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435&nbsp;<code>anotherFunc(num2)<\/code>&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435&nbsp;<code>num1 * num2<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>multiply(4, 5); <em>\/\/ =&gt; 20<\/em>\nmultiply(3, 3); <em>\/\/ =&gt; 9<\/em>\n\nconst double = multiply(2);\ndouble(5);  <em>\/\/ =&gt; 10<\/em>\ndouble(11); <em>\/\/ =&gt; 22<\/em><\/code><\/pre>\n\n\n\n<p><em>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442:<\/em><\/p>\n\n\n\n<p>\u0412\u043e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<code>multiply()<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function multiply(number1, number2) {\n  if (number2 !== undefined) {\n    return number1 * number2;\n  }\n  return function doMultiply(number2) {\n    return number1 * number2;\n  };\n}\n\nmultiply(4, 5); <em>\/\/ =&gt; 20<\/em>\nmultiply(3, 3); <em>\/\/ =&gt; 9<\/em>\n\nconst double = multiply(2);\ndouble(5);  <em>\/\/ =&gt; 10<\/em>\ndouble(11); <em>\/\/ =&gt; 22<\/em><\/code><\/pre>\n\n\n\n<p>\u2192&nbsp;<a href=\"https:\/\/jsitor.com\/k-NwrN59K\"><u>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e<\/u><\/a><\/p>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440&nbsp;<code>number2<\/code>&nbsp;\u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f&nbsp;<code>undefined<\/code>, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442&nbsp;<code>number1*number2<\/code>.<\/p>\n\n\n\n<p>\u041d\u043e \u0435\u0441\u043b\u0438&nbsp;<code>number2<\/code>&nbsp;\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f&nbsp;<code>undefined<\/code>, \u0442\u043e \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<code>multiply()<\/code>&nbsp;\u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0441 \u043e\u0434\u043d\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c.&nbsp; \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0435\u0440\u043d\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<code>doMultiply()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n\n\n\n<p><code>doMultiply()<\/code>&nbsp;\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u044b\u043a\u0430\u044e\u0449\u0435\u0439, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e&nbsp;<code>number1<\/code>&nbsp;\u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438&nbsp;<code>multiply()<\/code>.<\/p>\n\n\n\n<h3>\u0420\u0435\u0437\u044e\u043c\u0435<\/h3>\n\n\n\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435 \u0432\u0430\u0448\u0438 \u043e\u0442\u0432\u0435\u0442\u044b \u0441 \u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435:<\/p>\n\n\n\n<ul><li>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u043b\u0438 \u043d\u0430 5 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f\u0445.<\/li><li>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u043b\u0438 \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u043d\u0430 5 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u043d\u044c\u043a\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0442\u0435\u043c\u0443 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f,. \u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0439 \u043f\u043e\u0441\u0442&nbsp;<a href=\"https:\/\/dmitripavlutin.com\/simple-explanation-of-javascript-closures\/\"><u>A Simple Explanation of JavaScript Closures<\/u><\/a>&nbsp;(\u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f \u0432 JavaScript).<\/li><\/ul>\n\n\n\n<p>\u0413\u043e\u0442\u043e\u0432\u044b \u043a \u043d\u043e\u0432\u043e\u043c\u0443 \u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u044e? \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430&nbsp;<a href=\"https:\/\/dmitripavlutin.com\/javascript-this-interview-questions\/\"><u>7 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u044c\u044e \u043f\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u043c\u0443 \u0441\u043b\u043e\u0432\u0443 &#8220;this&#8221; \u0432 JavaScript<\/u><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a JavaScript \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 (closure). \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e JavaScript \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e \u0432\u0430\u0441 \u0441\u043f\u0440\u043e\u0441\u044f\u0442 \u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[132],"tags":[95],"_links":{"self":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/1717"}],"collection":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1717"}],"version-history":[{"count":1,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/1717\/revisions"}],"predecessor-version":[{"id":1718,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/1717\/revisions\/1718"}],"wp:attachment":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}