{"id":850,"date":"2025-08-05T16:36:55","date_gmt":"2025-08-05T07:36:55","guid":{"rendered":"https:\/\/nexive.tech\/?p=850"},"modified":"2025-08-05T16:36:55","modified_gmt":"2025-08-05T07:36:55","slug":"%e3%80%90%e3%82%b5%e3%82%af%e3%83%83%e3%81%a8%e8%a7%a3%e8%aa%ac%e3%80%91javascript%e3%81%ae%e5%a4%89%e6%95%b0%e5%ae%a3%e8%a8%80%ef%bc%88var-let-const%ef%bc%89%e3%81%ae%e9%81%95%e3%81%84","status":"publish","type":"post","link":"https:\/\/nexive.tech\/?p=850","title":{"rendered":"\u3010\u30b5\u30af\u30c3\u3068\u89e3\u8aac\u3011JavaScript\u306e\u5909\u6570\u5ba3\u8a00\uff08var, let, const\uff09\u306e\u9055\u3044"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JavaScript\u306e\u5909\u6570\u5ba3\u8a00\u306b\u4f7f\u308f\u308c\u308b <code>var<\/code>, <code>let<\/code>, <code>const<\/code> \u306e\u9055\u3044\u3092\u6b63\u78ba\u306b\u6574\u7406<\/li>\n\n\n\n<li>\u30b9\u30b3\u30fc\u30d7\u3001\u518d\u4ee3\u5165\u53ef\u5426\u3001\u5dfb\u304d\u4e0a\u3052\uff08\u30db\u30a4\u30b9\u30c6\u30a3\u30f3\u30b0\uff09\u306a\u3069\u306e\u4ed5\u69d8\u5dee\u3092\u660e\u793a<\/li>\n\n\n\n<li>\u5b9f\u52d9\u3067\u306e\u4f7f\u3044\u5206\u3051\u5224\u65ad\u3068\u6ce8\u610f\u70b9\u3092\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u4ed8\u304d\u3067\u89e3\u8aac<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. JavaScript\u306e\u5909\u6570\u5ba3\u8a00\uff08var, let, const\uff09\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>JavaScript\u3067\u306f\u3001\u5909\u6570\u3092\u5ba3\u8a00\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066 <code>var<\/code>, <code>let<\/code>, <code>const<\/code> \u306e3\u7a2e\u985e\u304c\u5b58\u5728\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><code>var<\/code>\u306fES5\u4ee5\u524d\u304b\u3089\u4f7f\u308f\u308c\u3066\u3044\u305f\u65e7\u6765\u306e\u5ba3\u8a00\u65b9\u6cd5\u3067\u3001\u95a2\u6570\u30b9\u30b3\u30fc\u30d7\u3068\u5dfb\u304d\u4e0a\u3052\u306e\u7279\u6027\u304c\u3042\u308a\u307e\u3059\u3002ES6\uff08ECMAScript 2015\uff09\u304b\u3089\u306f <code>let<\/code> \u3068 <code>const<\/code> \u304c\u5c0e\u5165\u3055\u308c\u3001\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u3092\u6301\u3064\u5ba3\u8a00\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u5b9f\u52d9\u3067\u306f\u3001\u518d\u4ee3\u5165\u306e\u5fc5\u8981\u304c\u3042\u308b\u5909\u6570\u306b\u306f <code>let<\/code> \u3092\u3001\u518d\u4ee3\u5165\u4e0d\u8981\u306a\u5b9a\u6570\u7684\u306a\u5909\u6570\u306b\u306f <code>const<\/code> \u3092\u4f7f\u3046\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<code>var<\/code>\u306f\u6b74\u53f2\u7684\u306a\u7406\u7531\u304c\u306a\u3044\u9650\u308a\u3001\u73fe\u5728\u3067\u306f\u63a8\u5968\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u8a73\u7d30\u89e3\u8aac<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b9\u30b3\u30fc\u30d7\u306e\u9055\u3044\uff08var\u306f\u95a2\u6570\u30b9\u30b3\u30fc\u30d7\u3001let\/const\u306f\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\uff09<\/h3>\n\n\n\n<p>\u6b21\u306e\u30b3\u30fc\u30c9\u306f\u3001\u30b9\u30b3\u30fc\u30d7\u306e\u9055\u3044\u306b\u3088\u308b\u6319\u52d5\u5dee\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>function exampleVar() {\n  if (true) {\n    var x = 10; \/\/ \u95a2\u6570\u30b9\u30b3\u30fc\u30d7\n  }\n  console.log(x); \/\/ 10\uff08var\u306f\u95a2\u6570\u30b9\u30b3\u30fc\u30d7\u306e\u305f\u3081\u30a2\u30af\u30bb\u30b9\u53ef\u80fd\uff09\n}\nexampleVar();\n\nfunction exampleLet() {\n  if (true) {\n    let y = 20; \/\/ \u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\n  }\n  console.log(y); \/\/ ReferenceError\uff08y\u306fif\u6587\u306e\u5916\u304b\u3089\u306f\u898b\u3048\u306a\u3044\uff09\n}\nexampleLet();\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">exampleVar<\/span><span style=\"color: #D4D4D4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #569CD6\">true<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">x<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">10<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u95a2\u6570\u30b9\u30b3\u30fc\u30d7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">x<\/span><span style=\"color: #D4D4D4\">); <\/span><span style=\"color: #6A9955\">\/\/ 10\uff08var\u306f\u95a2\u6570\u30b9\u30b3\u30fc\u30d7\u306e\u305f\u3081\u30a2\u30af\u30bb\u30b9\u53ef\u80fd\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">exampleVar<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">exampleLet<\/span><span style=\"color: #D4D4D4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #569CD6\">true<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">let<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">y<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">20<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">y<\/span><span style=\"color: #D4D4D4\">); <\/span><span style=\"color: #6A9955\">\/\/ ReferenceError\uff08y\u306fif\u6587\u306e\u5916\u304b\u3089\u306f\u898b\u3048\u306a\u3044\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">exampleLet<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u518d\u4ee3\u5165\u30fb\u518d\u5ba3\u8a00\u306e\u53ef\u5426<\/h3>\n\n\n\n<p><code>const<\/code>\u306f\u518d\u4ee3\u5165\u3082\u518d\u5ba3\u8a00\u3082\u4e0d\u53ef\u3001<code>let<\/code>\u306f\u518d\u4ee3\u5165\u53ef\u30fb\u518d\u5ba3\u8a00\u4e0d\u53ef\u3001<code>var<\/code>\u306f\u4e21\u65b9\u53ef\u3068\u3044\u3046\u9055\u3044\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>var a = 1;\nvar a = 2; \/\/ OK\uff08\u518d\u5ba3\u8a00\u53ef\u80fd\uff09\n\nlet b = 1;\nb = 2;     \/\/ OK\uff08\u518d\u4ee3\u5165\u53ef\u80fd\uff09\n\/\/ let b = 3; \/\/ SyntaxError\uff08\u518d\u5ba3\u8a00\u306f\u4e0d\u53ef\uff09\n\nconst c = 1;\n\/\/ c = 2;     \/\/ TypeError\uff08\u518d\u4ee3\u5165\u4e0d\u53ef\uff09\n\/\/ const c = 3; \/\/ SyntaxError\uff08\u518d\u5ba3\u8a00\u4e0d\u53ef\uff09\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">a<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">a<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ OK\uff08\u518d\u5ba3\u8a00\u53ef\u80fd\uff09<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">let<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">b<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">b<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">;     <\/span><span style=\"color: #6A9955\">\/\/ OK\uff08\u518d\u4ee3\u5165\u53ef\u80fd\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ let b = 3; \/\/ SyntaxError\uff08\u518d\u5ba3\u8a00\u306f\u4e0d\u53ef\uff09<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">const<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4FC1FF\">c<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ c = 2;     \/\/ TypeError\uff08\u518d\u4ee3\u5165\u4e0d\u53ef\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ const c = 3; \/\/ SyntaxError\uff08\u518d\u5ba3\u8a00\u4e0d\u53ef\uff09<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30db\u30a4\u30b9\u30c6\u30a3\u30f3\u30b0\uff08\u5dfb\u304d\u4e0a\u3052\uff09\u306e\u9055\u3044<\/h3>\n\n\n\n<p><code>var<\/code>\u306f\u5ba3\u8a00\u304c\u5dfb\u304d\u4e0a\u3052\u3089\u308c\u3001\u521d\u671f\u5316\u306f\u5dfb\u304d\u4e0a\u3052\u3089\u308c\u307e\u305b\u3093\u3002\u4e00\u65b9\u3001<code>let<\/code>\u3068<code>const<\/code>\u306f\u4e00\u6642\u7684\u6b7b\u89d2\uff08TDZ\uff09\u306b\u3088\u308a\u3001\u4f7f\u7528\u524d\u306b\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>console.log(foo); \/\/ undefined\uff08var\u306f\u5ba3\u8a00\u306e\u307f\u5dfb\u304d\u4e0a\u3052\uff09\nvar foo = 123;\n\n\/\/ console.log(bar); \/\/ ReferenceError\uff08let\u306fTDZ\u306e\u5f71\u97ff\uff09\nlet bar = 456;\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">foo<\/span><span style=\"color: #D4D4D4\">); <\/span><span style=\"color: #6A9955\">\/\/ undefined\uff08var\u306f\u5ba3\u8a00\u306e\u307f\u5dfb\u304d\u4e0a\u3052\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">foo<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">123<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ console.log(bar); \/\/ ReferenceError\uff08let\u306fTDZ\u306e\u5f71\u97ff\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">let<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">bar<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">456<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u3088\u304f\u3042\u308b\u30df\u30b9\u30fb\u8aa4\u89e3\u30fb\u843d\u3068\u3057\u7a74<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>const<\/code>\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5b9a\u7fa9\u3057\u305f\u969b\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5909\u66f4\u304c\u3067\u304d\u308b\u70b9\u306f\u8aa4\u89e3\u3055\u308c\u3084\u3059\u3044\u3067\u3059\u3002<code>const<\/code>\u306f<strong>\u5909\u6570\u306e\u518d\u4ee3\u5165\u3092\u7981\u6b62<\/strong>\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30df\u30e5\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u306f\u5236\u9650\u3057\u307e\u305b\u3093\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>const obj = { a: 1 };\nobj.a = 2; \/\/ OK\uff08\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5909\u66f4\u306f\u53ef\u80fd\uff09\nobj = {}; \/\/ TypeError\uff08\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5168\u4f53\u306e\u518d\u4ee3\u5165\u306f\u4e0d\u53ef\uff09\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">const<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4FC1FF\">obj<\/span><span style=\"color: #D4D4D4\"> = { <\/span><span style=\"color: #9CDCFE\">a:<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\"> };<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">obj<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">a<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ OK\uff08\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5909\u66f4\u306f\u53ef\u80fd\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">obj<\/span><span style=\"color: #D4D4D4\"> = {}; <\/span><span style=\"color: #6A9955\">\/\/ TypeError\uff08\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5168\u4f53\u306e\u518d\u4ee3\u5165\u306f\u4e0d\u53ef\uff09<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u306e\u5f71\u97ff\u3067\u3001for\u6587\u306e\u4e2d\u3067 <code>let<\/code> \u3092\u4f7f\u3046\u3068\u30eb\u30fc\u30d7\u3054\u3068\u306b\u30b9\u30b3\u30fc\u30d7\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>for (let i = 0; i &lt; 3; i++) {\n  setTimeout(() => console.log(i), 100);\n} \/\/ 0, 1, 2 \u3068\u51fa\u529b\u3055\u308c\u308b\n\nfor (var j = 0; j &lt; 3; j++) {\n  setTimeout(() => console.log(j), 100);\n} \/\/ 3, 3, 3 \u3068\u51fa\u529b\u3055\u308c\u308b\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #569CD6\">let<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> &lt; <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\">++) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #DCDCAA\">setTimeout<\/span><span style=\"color: #D4D4D4\">(() <\/span><span style=\"color: #569CD6\">=&gt;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #B5CEA8\">100<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><span style=\"color: #6A9955\">\/\/ 0, 1, 2 \u3068\u51fa\u529b\u3055\u308c\u308b<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #569CD6\">var<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">j<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #9CDCFE\">j<\/span><span style=\"color: #D4D4D4\"> &lt; <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #9CDCFE\">j<\/span><span style=\"color: #D4D4D4\">++) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #DCDCAA\">setTimeout<\/span><span style=\"color: #D4D4D4\">(() <\/span><span style=\"color: #569CD6\">=&gt;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">j<\/span><span style=\"color: #D4D4D4\">), <\/span><span style=\"color: #B5CEA8\">100<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><span style=\"color: #6A9955\">\/\/ 3, 3, 3 \u3068\u51fa\u529b\u3055\u308c\u308b<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u307e\u3068\u3081<\/h2>\n\n\n\n<p>JavaScript\u306e\u5909\u6570\u5ba3\u8a00\u306b\u306f3\u7a2e\u985e\u3042\u308a\u3001\u305d\u308c\u305e\u308c\u30b9\u30b3\u30fc\u30d7\u3084\u518d\u4ee3\u5165\u53ef\u5426\u3001\u30db\u30a4\u30b9\u30c6\u30a3\u30f3\u30b0\u306e\u6319\u52d5\u306b\u9055\u3044\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u57fa\u672c\u7684\u306b\u306f <code>const<\/code> \u3092\u512a\u5148\u7684\u306b\u4f7f\u3044\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066 <code>let<\/code> \u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002<code>var<\/code>\u306f\u975e\u63a8\u5968\u3067\u3042\u308a\u3001\u65e2\u5b58\u30b3\u30fc\u30c9\u4ee5\u5916\u3067\u306f\u907f\u3051\u308b\u306e\u304c\u7121\u96e3\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8 2. JavaScript\u306e\u5909\u6570\u5ba3\u8a00\uff08var, let, const\uff09\u3068\u306f\uff1f JavaScript\u3067\u306f\u3001\u5909\u6570\u3092\u5ba3\u8a00\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066 var, let, const \u306e3\u7a2e\u985e\u304c\u5b58\u5728\u3057\u307e\u3059\u3002 var\u306fE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":928,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[86],"tags":[],"class_list":["post-850","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/850","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=850"}],"version-history":[{"count":2,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/850\/revisions"}],"predecessor-version":[{"id":929,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/850\/revisions\/929"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/media\/928"}],"wp:attachment":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}