{"id":93367,"date":"2021-04-22T06:00:46","date_gmt":"2021-04-21T21:00:46","guid":{"rendered":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/?p=93367"},"modified":"2022-05-26T22:14:00","modified_gmt":"2022-05-26T13:14:00","slug":"javascript-difference-let-const","status":"publish","type":"post","link":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/2021\/04\/javascript-difference-let-const.html","title":{"rendered":"\u3010JavaScript\u306e\u57fa\u672c\u3011let\u3068const\u306e\u4f7f\u3044\u5206\u3051"},"content":{"rendered":"<p>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u884c\u3046\u969b\u306b\u3001\u975e\u5e38\u306b\u3088\u304f\u4f7f\u308f\u308c\u308b\u624b\u6cd5\u3068\u3057\u3066\u5909\u6570\u5ba3\u8a00\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u3053\u306e\u7bb1\u306b\u306f\u300112\u3068\u3044\u3046\u6570\u5024\u3092\u5165\u308c\u308b\u300d\u300c\u3042\u306e\u7bb1\u306b\u306f\u3001\u201dJavaScript\u201d\u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u5165\u308c\u308b\u300d\u306a\u3069\u3001\u5909\u6570\u306e\u540d\u524d\uff08\u7bb1\uff09\u3068\u3001\u5909\u6570\u306b\u683c\u7d0d\u3055\u308c\u308b\u30c7\u30fc\u30bf\uff08\u6587\u5b57\u5217\u3084\u6570\u5024\u306a\u3069\uff09\u3092\u6c7a\u3081\u3089\u308c\u308b\u306e\u304c\u5909\u6570\u5ba3\u8a00\u3067\u3059\u3002<\/p>\n<p>\u5ba3\u8a00\u3055\u308c\u305f\u5909\u6570\u306f\u3001\u7e70\u308a\u8fd4\u3057\u4f7f\u3048\u308b\u5229\u4fbf\u6027\u304c\u3042\u308a\u3001\u8a08\u7b97\u5f0f\u3084\u95a2\u6570\u3092\u4f5c\u308b\u5834\u9762\u3067\u6d3b\u8e8d\u3057\u307e\u3059\u3002<\/p>\n<p>JavaScript\u3067\u306f\u3001\u4e3b\u306b<code>let<\/code>\u3068<code>const<\/code>\u3092\u4f7f\u3063\u3066\u5909\u6570\u5ba3\u8a00\u3092\u884c\u3044\u307e\u3059\u304c\u3001\u3069\u3061\u3089\u3092\u4f7f\u3046\u3079\u304d\u304b\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f3\u306b\u60a9\u3080\u65b9\u3082\u5c11\u306a\u304f\u306a\u3044\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u4eca\u56de\u306f\u3001let\u3068const\u3092\u3046\u307e\u304f\u4f7f\u3044\u5206\u3051\u3089\u308c\u308b\u3088\u3046\u306b\u3001\u305d\u308c\u3089\u306e\u6027\u8cea\u3084\u30b9\u30b3\u30fc\u30d7\u3068\u306e\u95a2\u4fc2\u6027\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2 class=\"style2c\">var<\/h2>\n<p>let\u3068const\u306e\u6027\u8cea\u3092\u8aac\u660e\u3059\u308b\u524d\u306b\u3001<code>var<\/code>\u3068\u3044\u3046\u5909\u6570\u306b\u3064\u3044\u3066\u5c11\u3057\u88dc\u8db3\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u304c\u6642\u4ee3\u3068\u3068\u3082\u306b\u9032\u5316\u3057\u3066\u3044\u304f\u3088\u3046\u306b\u3001JavaScript\u3082\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u66f4\u65b0\u3055\u308c\u3066\u3044\u304d\u307e\u3059\u3002\u73fe\u5728\u6700\u65b0\u7248\u3068\u3057\u3066\u4f7f\u308f\u308c\u3066\u3044\u308b\u306e\u304c\u3001\u300cES6\uff08ECMAScript6\uff09\u300d\u3068\u3044\u3046\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u524d\u307e\u3067\u306f\u5909\u6570\u5ba3\u8a00\u306bvar\u306e\u307f\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001ES6\u306e\u74b0\u5883\u304b\u3089let\u3068const\u304c\u65b0\u305f\u306b\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\nvar\u306f\u30b9\u30b3\u30fc\u30d7\u306e\u7bc4\u56f2\u3092\u5e83\u3052\u308b\u81ea\u7531\u5ea6\u306e\u9ad8\u3044\u5909\u6570\u306e\u305f\u3081\u3001\u610f\u56f3\u3057\u3066\u3044\u306a\u3044\u30a8\u30e9\u30fc\u304c\u8d77\u3053\u308a\u5f97\u308b\u3053\u3068\u304b\u3089\u3001\u4f7f\u7528\u983b\u5ea6\u306f\u4f4e\u3044\u3067\u3059\u3002\u7279\u5225\u306a\u610f\u56f3\u304c\u306a\u3044\u9650\u308a\u306flet\u3068const\u3092\u4f7f\u3046\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>let\u3001 const\u3001 var\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<div class=\"s_table\"><table style=\"width: 100%; border-collapse: collapse;\">\n<tbody class=\"align1\">\n<tr>\n<td style=\"width: 25%; background-color: #f1f1f1;\"><\/td>\n<td style=\"width: 25%; background-color: #f1f1f1;\">let<\/td>\n<td style=\"width: 25%; background-color: #f1f1f1;\">const<\/td>\n<td style=\"width: 25%; background-color: #f1f1f1;\">var<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; background-color: #f9f9f9;\">\u518d\u4ee3\u5165<\/td>\n<td style=\"width: 25%;\">\u25cb<\/td>\n<td style=\"width: 25%;\">\u2613<\/td>\n<td style=\"width: 25%;\">\u25cb<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; background-color: #f9f9f9;\">\u518d\u5ba3\u8a00<\/td>\n<td style=\"width: 25%;\">\u2613<\/td>\n<td style=\"width: 25%;\">\u2613<\/td>\n<td style=\"width: 25%;\">\u25cb<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; background-color: #f9f9f9;\">\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7<\/td>\n<td style=\"width: 25%;\">\u25cb<\/td>\n<td style=\"width: 25%;\">\u25cb<\/td>\n<td style=\"width: 25%;\">\u2613<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; background-color: #f9f9f9;\">\u95a2\u6570\u30b9\u30b3\u30fc\u30d7<\/td>\n<td style=\"width: 25%;\">\u25cb<\/td>\n<td style=\"width: 25%;\">\u25cb<\/td>\n<td style=\"width: 25%;\">\u25cb<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<h2 class=\"style2c\">let\u3068const\u306e\u4f7f\u3044\u65b9<\/h2>\n<p>\u3053\u3053\u304b\u3089\u306f\u3001let\u3068const\u306e\u4f7f\u3044\u65b9\u3092\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h3 class=\"style3c\">\u5909\u6570\u5ba3\u8a00<\/h3>\n<p>let\u3068const\u306e\u5ba3\u8a00\u65b9\u6cd5\u306b\u9055\u3044\u306f\u306a\u304f\u3001\u6587\u5b57\u5217\u3084\u6570\u5b57\u3001\u914d\u5217\u306a\u3069\u3092\u683c\u7d0d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ let\r\nlet number = 1;\r\nlet string = 'let\u306e\u5834\u5408';\r\nlet array = [a, b, c];\r\nlet object = {id: 1, name: 'yamada'};\r\n\r\nconsole.log(number); \/\/ 1\r\nconsole.log(string); \/\/ let\u306e\u5834\u5408\r\nconsole.log(array[2]); \/\/ c\r\nconsole.log(object.name); \/\/ yamada\r\n\r\n\/\/ const\r\nconst number = 50;\r\nconst string = 'const\u306e\u5834\u5408';\r\nconst array = [x, y, z];\r\nconst object = {color: 'yellow', price: 500};\r\n\r\nconsole.log(number); \/\/ 50\r\nconsole.log(string); \/\/ const\u306e\u5834\u5408\r\nconsole.log(array[0]); \/\/ x\r\nconsole.log(object.price); \/\/ 500<span style=\"background-color: initial; font-family: Consolas, Monaco, monospace; font-size: 12px; color: #333333;\"><\/span><\/code><\/pre>\n<\/div>\n<p>\u5024\u306e\u53c2\u7167\u304c\u5fc5\u8981\u306a\u5834\u5408\u3084\u3001\u4ed6\u306e\u95a2\u6570\u306b\u518d\u5229\u7528\u3059\u308b\u3068\u304d\u306a\u3069\u306b\u4f7f\u308f\u308c\u307e\u3059\u3002<\/p>\n<h3 class=\"style3c\">\u518d\u4ee3\u5165<\/h3>\n<p>\u4e00\u5ea6\u5ba3\u8a00\u3057\u305f\u5909\u6570\u3092\u66f4\u65b0\u3059\u308b\u3053\u3068\u3092\u518d\u4ee3\u5165\u3068\u3044\u3044\u307e\u3059\u3002<br \/>\nlet\u306f\u5024\u306e\u518d\u4ee3\u5165\u304c\u3067\u304d\u308b\u4e00\u65b9\u3067\u3001const\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ let\r\nlet a = 1; \/\/ \u5909\u6570\u5ba3\u8a00 \r\na = 10; \/\/ \u518d\u4ee3\u5165 \r\n\r\nconsole.log(a); \/\/ 10<\/code><\/pre>\n<\/div>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ const\r\nconst b = 1; \/\/ \u5909\u6570\u5ba3\u8a00 \r\nb = 10; \/\/ \u518d\u4ee3\u5165 \r\n\r\nconsole.log(b); \/\/ Assignment to constant variable.<\/code><\/pre>\n<\/div>\n<p>\u5909\u6570\u3092\u518d\u4ee3\u5165\u3059\u308b\u30b1\u30fc\u30b9\u306f\u3042\u307e\u308a\u591a\u304f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30eb\u30fc\u30d7\u51e6\u7406\u306a\u3069\u306e\u5909\u6570\u306e\u6570\u5024\u304c\u5909\u308f\u308b\u3088\u3046\u306a\u5834\u5408\u306a\u3069\u306b\u3001let\u3092\u7528\u3044\u3066\u518d\u4ee3\u5165\u3092\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3054\u3068\u306b\u3001\u56de\u6570\u3092\u30ab\u30a6\u30f3\u30c8\u3057\u3001\u30ab\u30a6\u30f3\u30c8\u6570\u5024\u3092\u4fdd\u6301\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306a\u3069\u306b\u3001let\u304c\u5f79\u306b\u7acb\u3061\u307e\u3059\u3002<\/p>\n<h3 class=\"style3c\">\u518d\u5ba3\u8a00<\/h3>\n<p>\u4e00\u5ea6\u5ba3\u8a00\u3057\u305f\u5909\u6570\u3092\u3001\u540c\u3058\u5909\u6570\u540d\u3092\u4f7f\u3063\u3066\u518d\u3073\u5ba3\u8a00\u3092\u3057\u76f4\u3059\u3053\u3068\u3092\u518d\u5ba3\u8a00\u3068\u8a00\u3044\u307e\u3059\u3002<br \/>\nlet\u3068const\u3069\u3061\u3089\u30822\u56de\u4ee5\u4e0a\u5ba3\u8a00\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ let\r\nlet a = 1; \/\/ \u5909\u6570\u5ba3\u8a00 \r\nlet a = 10; \/\/ \u518d\u5ba3\u8a00 \r\n\r\nconsole.log(a); \/\/ SyntaxError: Identifier 'a' has already been declared<\/code><\/pre>\n<\/div>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ const\r\nconst b = 1; \/\/ \u5909\u6570\u5ba3\u8a00 \r\nconst b = 10; \/\/ \u518d\u5ba3\u8a00 \r\n\r\nconsole.log(b); \/\/ SyntaxError: Identifier 'b' has already been declared<\/code><\/pre>\n<\/div>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u9577\u304f\u306a\u3063\u3066\u304f\u308b\u3068\u3001\u8aa4\u3063\u3066\u540c\u3058\u5909\u6570\u540d\u3092\u3064\u3051\u3066\u3057\u307e\u3046\u3053\u3068\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u518d\u5ba3\u8a00\u304c\u3067\u304d\u306a\u3044\u30e1\u30ea\u30c3\u30c8\u3068\u3057\u3066\u3001\u3053\u306e\u3088\u3046\u306b\u5225\u7528\u9014\u306e\u5909\u6570\u306b\u540c\u3058\u5909\u6570\u540d\u3092\u3064\u3051\u3066\u3057\u307e\u3046\u3053\u3068\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2 class=\"style2c\">\u30b9\u30b3\u30fc\u30d7<\/h2>\n<p>\u30b9\u30b3\u30fc\u30d7\u3068\u306f\u3001\u5909\u6570\u3084\u95a2\u6570\u306e\u6709\u52b9\u7bc4\u56f2\u306e\u3053\u3068\u3067\u3059\u3002<br \/>\n\u901a\u5e38\u3001\u3042\u308b\u5909\u6570\u306e\u6709\u52b9\u7bc4\u56f2\u5916\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3057\u3088\u3046\u3068\u3057\u3066\u3082\u3001\u305d\u306e\u5909\u6570\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\n\u30b9\u30b3\u30fc\u30d7\u3092\u610f\u8b58\u3059\u308b\u3053\u3068\u3067\u3001\u4e88\u671f\u305b\u306c\u4e0d\u5177\u5408\u3092\u9632\u304e\u3001\u3088\u308a\u5b89\u5168\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30b3\u30fc\u30d7\u306b\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u30b9\u30b3\u30fc\u30d7\u3068\u30ed\u30fc\u30ab\u30eb\u30b9\u30b3\u30fc\u30d7\u306e2\u7a2e\u985e\u304c\u5b58\u5728\u3057\u307e\u3059\u3002<\/p>\n<h3 class=\"style3c\">\u30b0\u30ed\u30fc\u30d0\u30eb\u30b9\u30b3\u30fc\u30d7<\/h3>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u3069\u3053\u304b\u3089\u3067\u3082\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u7bc4\u56f2\u306e\u3053\u3068\u3092\u30b0\u30ed\u30fc\u30d0\u30eb\u30b9\u30b3\u30fc\u30d7\u3068\u8a00\u3044\u307e\u3059\u3002<br \/>\n\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4e00\u756a\u5916\u5074\u3059\u306a\u308f\u3061\u30c8\u30c3\u30d7\u3067\u5ba3\u8a00\u3055\u308c\u305flet, const, var\u3044\u305a\u308c\u304b\u306e\u5909\u6570\u306f\u3001\u30b0\u30ed\u30fc\u30d0\u30b9\u30b3\u30fc\u30d7\u3092\u6301\u3061\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u30b9\u30b3\u30fc\u30d7\u3092\u6301\u3064\u5909\u6570\u306e\u3053\u3068\u3092\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3068\u8a00\u3044\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>let a = 1; \r\nconsole.log(a); \/\/1 \r\n\r\nfunction global() {\r\n \u3000console.log(a);\r\n} \r\n\r\nglobal(); \r\n\/\/ 1<\/code><\/pre>\n<\/div>\n<p>\u30c8\u30c3\u30d7\u76f4\u4e0b\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u3084\u95a2\u6570\u5185\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u4e00\u756a\u5916\u5074\u3067\u5ba3\u8a00\u3057\u305f\u5909\u6570<code>a<\/code>\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u30b9\u30b3\u30fc\u30d7\u3092\u6301\u3061\u3001\u3042\u3089\u3086\u308b\u5834\u6240\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3092\u8a31\u3057\u307e\u3059\u3002<\/p>\n<h3 class=\"style3c\">\u30ed\u30fc\u30ab\u30eb\u30b9\u30b3\u30fc\u30d7<\/h3>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u7279\u5b9a\u306e\u7bc4\u56f2\u5185\u3067\u30a2\u30af\u30bb\u30b9\u3092\u8a31\u53ef\u3059\u308b\u5909\u6570\u306e\u3053\u3068\u3092\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3068\u547c\u3073\u3001\u305d\u306e\u5909\u6570\u304c\u6301\u3064\u6709\u52b9\u7bc4\u56f2\u306e\u3053\u3068\u3092\u30ed\u30fc\u30ab\u30eb\u30b9\u30b3\u30fc\u30d7\u3068\u547c\u3073\u307e\u3059\u3002<br \/>\n\u30ed\u30fc\u30ab\u30eb\u30b9\u30b3\u30fc\u30d7\u306f\u3001\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u3068\u95a2\u6570\u30b9\u30b3\u30fc\u30d7\u306e2\u7a2e\u985e\u306b\u5206\u985e\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h4 class=\"style3c\">\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7<\/h4>\n<p>\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u3068\u306f\u3001\u30d6\u30ed\u30c3\u30af<code>{}<\/code>\u3054\u3068\u306b\u56f2\u307e\u308c\u305f\u7bc4\u56f2\u306e\u3053\u3068\u3067\u3059\u3002<br \/>\n\u30d6\u30ed\u30c3\u30af\u5185\u3067let\u3084const\u3067\u5ba3\u8a00\u3055\u308c\u305f\u5909\u6570\u306f\u3001\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u3092\u4f5c\u308a\u3001\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u5916\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u3092\u5236\u9650\u3057\u307e\u3059\u3002<\/p>\n<p>\u4e00\u65b9\u3001var\u3067\u5ba3\u8a00\u3055\u308c\u305f\u5909\u6570\u306f\u3001\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u3092\u6301\u3064\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u3001\u5916\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u3092\u8a31\u53ef\u3057\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>{\r\n \u3000let a = 1;\r\n \u3000const b = 10;\r\n \u3000var c = 100;\r\n} \r\n\r\nconsole.log(a); \/\/ ReferenceError: a is not defined\r\nconsole.log(b); \/\/ ReferenceError: b is not defined\r\nconsole.log(c); \/\/ 100<\/code><\/pre>\n<\/div>\n<p>let\u3068const\u306f\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u3092\u4f5c\u308b\u305f\u3081\u30a8\u30e9\u30fc\u304c\u8fd4\u3063\u3066\u304d\u307e\u3059\u304c\u3001var\u306e\u5834\u5408\u306f\u3001\u30d6\u30ed\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u3092\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u305f\u3081\u3001\u5024\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\nvar\u3067\u5ba3\u8a00\u3055\u308c\u305f\u5909\u6570\u306f\u3001\u81ea\u7531\u5ea6\u304c\u9ad8\u304f\u4e00\u898b\u4fbf\u5229\u305d\u3046\u306b\u3082\u601d\u3048\u307e\u3059\u304c\u3001\u3069\u3053\u304b\u3089\u3067\u3082\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u610f\u56f3\u305b\u305a\u306b\u5024\u3092\u5909\u66f4\u3057\u3066\u3057\u307e\u3046\u6050\u308c\u304c\u3042\u308b\u305f\u3081\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<h4 class=\"style3c\">\u95a2\u6570\u30b9\u30b3\u30fc\u30d7<\/h4>\n<p>\u95a2\u6570\u30b9\u30b3\u30fc\u30d7\u3068\u306f\u3001\u95a2\u6570\u306e\u30d6\u30ed\u30c3\u30af<code>{}<\/code>\u3054\u3068\u306b\u4f5c\u3089\u308c\u308b\u7bc4\u56f2\u306e\u3053\u3068\u3067\u3059\u3002<br \/>\n\u95a2\u6570\u30b9\u30b3\u30fc\u30d7\u5185\u3067let\u3001const\u3001var\u306e\u3044\u305a\u308c\u304b\u3067\u5ba3\u8a00\u3055\u308c\u305f\u5909\u6570\u306f\u3001\u95a2\u6570\u30b9\u30b3\u30fc\u30d7\u306e\u5916\u304b\u3089\u306f\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function scope() {\r\n \u3000let a = 1;\r\n \u3000const b = 10;\r\n \u3000var c = 100;\r\n\r\n \u3000a = 2; \/\/ \u518d\u4ee3\u5165\r\n\r\n \u3000console.log(a); \r\n \u3000console.log(b); \r\n \u3000console.log(c); \r\n} \r\n\r\nscope(); \r\n\/\/ 2\r\n\/\/ 10\r\n\/\/ 100\r\n\r\nconsole.log(a); \/\/ReferenceError: a is not defined\r\nconsole.log(b); \/\/ReferenceError: b is not defined\r\nconsole.log(c); \/\/ReferenceError: c is not defined<\/code><\/pre>\n<\/div>\n<p>\u95a2\u6570\u306e\u30d6\u30ed\u30c3\u30af\u5185\u3067\u5909\u6570\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3082\u306e\u306f\u3001\u305d\u308c\u305e\u308c\u5024\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u95a2\u6570\u306e\u30d6\u30ed\u30c3\u30af\u5916\u304b\u3089\u306f\u30a2\u30af\u30bb\u30b9\u3067\u304d\u306a\u3044\u305f\u3081\u3001\u30a8\u30e9\u30fc\u3068\u306a\u308a\u3001\u5024\u3092\u53c2\u7167\u3067\u304d\u306a\u3044\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<code><\/code><\/p>\n<h2 class=\"style2c\">let\u3068const\u3069\u3061\u3089\u3092\u4f7f\u3046\u3079\u304d\u304b<\/h2>\n<p>\u57fa\u672c\u7684\u306b\u306fconst\u3092\u4f7f\u3046\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002\u518d\u4ee3\u5165\u3084\u518d\u5ba3\u8a00\u304c\u3067\u304d\u305a\u5236\u7d04\u304c\u591a\u3044\u304b\u3089\u3053\u305d\u3001\u610f\u56f3\u3057\u306a\u3044\u6319\u52d5\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u308b\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>const\u3067\u306f\u5b9f\u88c5\u3067\u304d\u306a\u3044\u5909\u6570\u306e\u518d\u4ee3\u5165\u304c\u5fc5\u8981\u306a\u3068\u304d\u306flet\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306f\u3001let\u3092\u4f7f\u3046\u3079\u304d\u5834\u5408\u306e\u5177\u4f53\u4f8b\u3067\u3059\u3002\u4f8b\u3048\u3070for\u6587\u306e\u30a4\u30c6\u30ec\u30fc\u30bf\u306b\u306flet\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>for (let i = 0; i &lt; 3; i++) {\r\n console.log(i);\r\n}<\/code><\/pre>\n<\/div>\n<h2 class=\"style2c\">\u307e\u3068\u3081<\/h2>\n<p>\u4eca\u56de\u306f\u3001\u5909\u6570\u306e\u7279\u5fb4\u3084\u30b9\u30b3\u30fc\u30d7\u3068\u306e\u95a2\u4fc2\u6027\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u5909\u6570\u306e\u6271\u3044\u65b9\u3084\u5fc5\u8981\u6027\u3092\u610f\u8b58\u3059\u308b\u3053\u3068\u3067\u3001\u5b89\u5168\u3067\u5206\u304b\u308a\u3084\u3059\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u3051\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\nlet\u3084const\u3092\u4f7f\u3044\u5206\u3051\u3089\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2 class=\"style5\">\u5909\u6570\u306e\u95a2\u9023\u8a18\u4e8b<\/h2>\n<p>\u30fb<a href=\"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/2022\/02\/javascript-variables.html\"><strong>\u5909\u6570\u3068\u5ba3\u8a00<\/strong><\/a><br \/>\n\u30fb<a href=\"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/2022\/02\/javascript-variable-rule.html\"><strong>\u5909\u6570\u540d\u306e\u30eb\u30fc\u30eb\u3068\u547d\u540d\u898f\u5247<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u884c\u3046\u969b\u306b\u3001\u975e\u5e38\u306b\u3088\u304f\u4f7f\u308f\u308c\u308b\u624b\u6cd5\u3068\u3057\u3066\u5909\u6570\u5ba3\u8a00\u304c\u3042\u308a\u307e\u3059\u3002 \u4f8b\u3048\u3070\u3001\u300c\u3053\u306e\u7bb1\u306b\u306f\u300112\u3068\u3044\u3046\u6570\u5024\u3092\u5165\u308c\u308b\u300d\u300c\u3042\u306e\u7bb1\u306b\u306f\u3001\u201dJavaScript\u201d\u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u5165\u308c\u308b\u300d\u306a\u3069\u3001\u5909\u6570\u306e\u540d\u524d\uff08\u7bb1\uff09\u3068\u3001\u5909\u6570\u306b\u683c\u7d0d\u3055 [&hellip;]","protected":false},"author":1,"featured_media":127577,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1142],"tags":[964],"class_list":["post-93367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript-basic","tag-javascript"],"_links":{"self":[{"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/posts\/93367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/comments?post=93367"}],"version-history":[{"count":0,"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/posts\/93367\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/media\/127577"}],"wp:attachment":[{"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/media?parent=93367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/categories?post=93367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anthem00.xsrv.jp\/2023_new_tcd\/wp-json\/wp\/v2\/tags?post=93367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}