ex) function ex1(){ console.log(this); // this : window객체 }
ex1();
// this로 전역변수를 호출할 경우
var name = 'chris'; // 전역변수
function ex1(){ console.log(this.name); // 전역객체(this)를 통해 전역변수(name)에 접근 }
ex1(); // this.name == window.name >> 'chris'
ex) 'use strict'; // 엄격모드 사용
var name = 'chris'; // 전역변수
function ex2() { console.log(this.name); // this == undifined (속성이 없음) }
ex2(); // error 출력
ex) var age = 100; // 전역변수