2; const c = 3; console.log(a, b, c); جຊతʹ var Ͱ let Ͱ const ͰมΛએݴ͢Δͱ͍͏ҙຯͰҰॹͰ͢ɻ ͪͳΈʹͲΕΛҰ൪͏͔ͱ͍͏ͱɺ const > let >>>>>>(ӽ͑ΒΕͳ͍น)>>>>>>> var ͘Β͍ͷॱͰ͍·͢ɻ
2; const c = 3; ͜ΕશͯάϩʔόϧείʔϓͰ͢ɻ function foo() { var a = 1; let b = 2; const c = 3; } ͜ΕશͯϩʔΧϧείʔϓͰ͢ɻ function bar() { { var a = 1; //͜Ε͚ͩϩʔΧϧείʔϓ let b = 2; // let ͱ const ϒϩοΫείʔϓ const c = 3; } console.log(a) // 1, b ͱ c ͔͜͜ΒݟΕͳ͍ }
͕ؔݺͼग़࣌͠ʹಈతʹܾఆ͞ΕΔɻ const B = { foo: function() { console.log(this); } } B.foo() // class B const a = B.foo; a() // global object const a = B.foo.bind(B);