{"id":7909,"date":"2026-01-03T13:21:39","date_gmt":"2026-01-03T10:21:39","guid":{"rendered":"https:\/\/1.cbm.ua\/?p=7909"},"modified":"2026-01-13T19:38:22","modified_gmt":"2026-01-13T16:38:22","slug":"%d1%81%d1%82%d1%80%d0%b5%d0%bb%d0%be%d1%87%d1%8b%d0%b5-%d1%84%d1%83%d0%bd%d0%ba%d0%b8%d0%b8-%d0%b2-js-user-user-age-18-user-user-age-18-user-age-0","status":"publish","type":"post","link":"https:\/\/1.cbm.ua\/?p=7909","title":{"rendered":"\u0421\u0442\u0440\u0435\u043b\u043e\u0447\u044b\u0435 \u0444\u0443\u043d\u043a\u0438\u0438 \u0432 JS. (user => user.age >= 18) (user &amp;&amp; user.age >= 18) (user?.age ?? 0)"},"content":{"rendered":"\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u0443\u043d\u043a\u0438\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ users.js\n\nexport const filterAdults = (users) =&gt; {\n\n&nbsp; return users.filter(user =&gt; user.age &gt;= 18);\n\n};<\/code><\/pre>\n\n\n\n<p>\u041a\u0430\u043a \u0435\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u0412 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>filterAdults<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432 \u043d\u0435\u0451 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 (\u0438\u043b\u0438 <code>null<\/code>), JavaScript \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 <code>TypeError: users.filter is not a function<\/code>. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0443 \u0441\u0442\u0440\u043e\u043a \u043d\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 <code>.filter()<\/code>.<\/p>\n\n\n\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0439 (&#171;\u043f\u0443\u043b\u0435\u043d\u0435\u043f\u0440\u043e\u0431\u0438\u0432\u0430\u0435\u043c\u043e\u0439&#187;).<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 (\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435)<\/h2>\n\n\n\n<p>\u0421\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 <code>users<\/code> \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u043d \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c.<\/p>\n\n\n\n<p>JavaScript<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export const filterAdults = (users) => {\n  \/\/ \u0415\u0441\u043b\u0438 users \u2014 \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, null \u0438\u043b\u0438 \u043d\u0435 \u043c\u0430\u0441\u0441\u0438\u0432, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\n  if (!Array.isArray(users)) {\n    return [];\n  }\n\n  return users.filter(user => user &amp;&amp; user.age >= 18);\n};\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 (\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e)<\/h2>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 <code>undefined<\/code>, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041d\u043e \u0434\u043b\u044f <strong>\u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438<\/strong> \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044b:<\/p>\n\n\n\n<p>JavaScript<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export const filterAdults = (users = []) => {\n  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u0448\u0435\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0430\u0441\u0441\u0438\u0432\n  if (!Array.isArray(users)) return [];\n\n  return users.filter(user => user?.age >= 18);\n};\n<\/pre>\n\n\n\n<p><em>\u0417\u0434\u0435\u0441\u044c <code>user?.age<\/code> (optional chaining) \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f <code>null<\/code>.<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e? (\u041b\u043e\u0433\u0438\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438)<\/h2>\n\n\n\n<p>\u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0431\u044b\u0447\u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <strong>\u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 <code>[]<\/code><\/strong>, \u0447\u0435\u043c <code>null<\/code> \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0446\u0438\u043a\u043b \u0432 React) \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u043b\u0441\u044f.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 (Guard Clauses)<\/h2>\n\n\n\n<p>\u0412 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 &#171;\u0437\u0430\u0449\u0438\u0442\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f&#187; (Guard Clauses) \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u0447\u0438\u0449\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0435 \u043f\u0440\u044f\u0447\u0435\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 <code>if\/else<\/code>.<\/p>\n\n\n\n<p>JavaScript<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export const filterAdults = (users) => {\n  \/\/ 1. \"\u0412\u044b\u0448\u0438\u0431\u0430\u0435\u043c\" \u043f\u043b\u043e\u0445\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0440\u0430\u0437\u0443\n  const isInvalid = !users || !Array.isArray(users);\n  if (isInvalid) return [];\n\n  \/\/ 2. \u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0437\u043d\u0430\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432\n  return users.filter(user => {\n    \/\/ \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430: \u0435\u0441\u0442\u044c \u043b\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e\u043b\u0435 age\n    return typeof user.age === 'number' &amp;&amp; user.age >= 18;\n  });\n};\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u0427\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c:<\/strong> \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 &#171;\u043f\u0430\u0434\u0435\u043d\u0438\u0435&#187; \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/li>\n\n\n\n<li><strong>\u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0441\u0442\u044c:<\/strong> \u041e\u043d\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 (\u043b\u0438\u0431\u043e \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043b\u0438\u0431\u043e \u043f\u0443\u0441\u0442\u043e\u0439).<\/li>\n\n\n\n<li><strong>\u0413\u0438\u0431\u043a\u043e\u0441\u0442\u044c:<\/strong> \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 <code>typeof user.age<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u042f \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e \u043a\u0430\u043a \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c &#171;<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-nv-c-2-color\">user?.age<\/mark>&#187; \u0438 \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0435 \u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 ?<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u00ab\u0420\u0430\u043d\u044c\u0448\u0435\u00bb \u0438 \u00ab\u0421\u0435\u0439\u0447\u0430\u0441\u00bb<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td><strong>\u0427\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c<\/strong><\/td><td><strong>\u0420\u0430\u043d\u044c\u0448\u0435 (ES5\/ES6)<\/strong><\/td><td><strong>\u0421\u0435\u0439\u0447\u0430\u0441 (ES2020+)<\/strong><\/td><\/tr><\/thead><tbody><tr><td><strong>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f<\/strong><\/td><td><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-3-color\">user &amp;&amp; user.age<\/mark><\/code><\/td><td><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-nv-c-2-color\">user?.age<\/mark><\/code><\/td><\/tr><tr><td><strong>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/strong><\/td><td><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-6-color\">user.age !== undefined ? user.age : 0<\/mark><\/code><\/td><td><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-4-color\">user?.age ?? 0<\/mark><\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u0418\u0442\u043e\u0433<\/h3>\n\n\n\n<p>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-nv-c-2-color\">user?.age<\/mark><\/code> &gt;= 18<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 <code>if (user != null &amp;&amp; user.age &gt;= 18)<\/code>, \u043d\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. JavaScript \u0441\u0430\u043c \u0431\u0435\u0440\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0440\u0443\u0442\u0438\u043d\u0443 \u043f\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u043d\u0430 <code>null<\/code> \u0438 <code>undefined<\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 <code>user &amp;&amp; user.age<\/code><\/h3>\n\n\n\n<p>\u042d\u0442\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 <strong>&#171;\u043f\u0440\u0430\u0432\u0434\u0438\u0432\u043e\u0441\u0442\u044c&#187;<\/strong> (truthiness) \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0415\u0441\u043b\u0438 <code>user<\/code> \u2014<mark style=\"background-color:var(--custom-1)\" class=\"has-inline-color\"> \u044d\u0442\u043e \u043b\u044e\u0431\u0430\u044f \u00ab\u043b\u043e\u0436\u044c\u00bb (<code>null<\/code>, <code>undefined<\/code>, <code>0<\/code>, <code>false<\/code>, <code>\"\"<\/code>)<\/mark>, \u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0440\u0432\u0435\u0442\u0441\u044f \u0438 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u00ab\u043b\u043e\u0436\u043d\u043e\u0435\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/li>\n\n\n\n<li><strong>\u0412 \u0447\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430:<\/strong> \u0415\u0441\u043b\u0438 <code>user<\/code> \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0438\u0441\u043b\u0443 <code>0<\/code>, \u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <code>0 &amp;&amp; 0.age<\/code> \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430 \u043d\u0443\u043b\u0435, \u0445\u043e\u0442\u044f \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0443 \u0447\u0438\u0441\u043b\u0430 \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 (\u0445\u043e\u0442\u044c \u044d\u0442\u043e \u0438 \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-nv-c-2-color\">user?.age<\/mark><\/code> (Optional Chaining)<\/h3>\n\n\n\n<p>\u042d\u0442\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <strong>\u0441\u0442\u0440\u043e\u0436\u0435<\/strong>. \u041e\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u00ab\u043f\u0443\u0441\u0442\u043e\u0442\u0443\u00bb: <code>null<\/code> \u0438\u043b\u0438 <code>undefined<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0415\u0441\u043b\u0438 <code>user<\/code> \u2014 \u044d\u0442\u043e <code>0<\/code>, <code>false<\/code> \u0438\u043b\u0438 <code>\"\"<\/code> (\u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430), \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>?.<\/code> <strong>\u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f<\/strong>. \u041e\u043d \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0443 \u043d\u0435\u0433\u043e <code>.age<\/code>.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u041d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445<\/h3>\n\n\n\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c, \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>user<\/code> \u043f\u043e\u043f\u0430\u043b\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td><strong>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 user<\/strong><\/td><td><strong>user &amp;&amp; user.age<\/strong><\/td><td><strong>user?.age<\/strong><\/td><td><strong>\u0420\u0430\u0437\u043d\u0438\u0446\u0430<\/strong><\/td><\/tr><\/thead><tbody><tr><td><code>{ age: 20 }<\/code><\/td><td><code>20<\/code><\/td><td><code>20<\/code><\/td><td>\u041e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e<\/td><\/tr><tr><td><code>null<\/code><\/td><td><code>null<\/code><\/td><td><code>undefined<\/code><\/td><td>\u041e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e (\u043e\u0431\u0430 &#171;\u043b\u043e\u0436\u043d\u044b\u0435&#187;)<\/td><\/tr><tr><td><code>undefined<\/code><\/td><td><code>undefined<\/code><\/td><td><code>undefined<\/code><\/td><td>\u041e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e<\/td><\/tr><tr><td><strong><code>0<\/code><\/strong> (\u0447\u0438\u0441\u043b\u043e)<\/td><td><strong><code><mark style=\"background-color:var(--custom-1)\" class=\"has-inline-color has-nv-dark-bg-color\">0<\/mark><\/code><\/strong><\/td><td><strong><mark style=\"background-color:var(--custom-1)\" class=\"has-inline-color\">\u041e\u0448\u0438\u0431\u043a\u0430!<\/mark><\/strong><\/td><td><strong><mark style=\"background-color:var(--custom-1)\" class=\"has-inline-color has-nv-dark-bg-color\">\u0420\u0430\u0437\u043d\u0438\u0446\u0430!<\/mark><\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u043d\u0435\u0442 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u00ab\u0418\u041b\u0418\u00bb <mark style=\"background-color:var(--custom-5)\" class=\"has-inline-color has-nv-dark-bg-color\"><code>user || user.age<\/code><\/mark><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u0443\u043d\u043a\u0438\u0438: \u041a\u0430\u043a \u0435\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430. \u0412 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f filterAdults \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432 \u043d\u0435\u0451 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 (\u0438\u043b\u0438 null), JavaScript \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 TypeError: users.filter is not a function. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0443 \u0441\u0442\u0440\u043e\u043a \u043d\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 .filter(). \u0412\u043e\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u0431\u044b\u043b\u0430&hellip;&nbsp;<a href=\"https:\/\/1.cbm.ua\/?p=7909\" rel=\"bookmark\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 &raquo;<span class=\"screen-reader-text\">\u0421\u0442\u0440\u0435\u043b\u043e\u0447\u044b\u0435 \u0444\u0443\u043d\u043a\u0438\u0438 \u0432 JS. (user => user.age >= 18) (user &amp;&amp; user.age >= 18) (user?.age ?? 0)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[194,6],"tags":[],"class_list":["post-7909","post","type-post","status-publish","format-standard","hentry","category-spr-jk_pwa-1","category-js"],"_links":{"self":[{"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/posts\/7909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7909"}],"version-history":[{"count":1,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/posts\/7909\/revisions"}],"predecessor-version":[{"id":7911,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=\/wp\/v2\/posts\/7909\/revisions\/7911"}],"wp:attachment":[{"href":"https:\/\/1.cbm.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1.cbm.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}