<aside> 💡 Study Note 전역 객체를 알아봅시다 :)

</aside>

전역 객체

: 코드가 실행되기 전에 자바스크립트 엔진에 의해 가장 먼저 생성되는 특수한 최상위 객체

계층적 구조상 어떤 객체에도 속하지 않은 빌트인 객체의 최상위 객체

⇒ 개발자가 의도적으로 생성할 수 없다. ( 전역 객체를 생성할 함수 제공 X)

⇒ 전역 객체의 프로퍼티를 참조할 때 window 생략 가능

window.parseInt('F', 16);

parseInt('F', 16);

// 15 => 16진수로 해석된 문자열 'F'를 10진수로 변환

⇒ Object, String, Number, Boolean, Function, Array, Date, RegExp, Math, Promise 같은 모든 표준 빌트인 객체를 프로퍼티로 가짐

⇒ var 키워드로 선언한 전역 변수 & 값이 할당된 선언하지 않은 변수 & 전역 함수는 전역 객체의 프로퍼티

var foo = 1;
console.log(window.foo); // 1

bar = 2;
console.log(window.bar); // 2

function baz() { return 3; }
console.log(window.baz()); // 3 

let foo = 123;
console.log(window.foo); // undefined

빌트인 전역 프로퍼티

: 전역 객체의 프로퍼티

1. Infinity

: 무한대를 나타내는 숫자값 Infinity를 갖는다.

console.log(3/0);   // Infinity
console.log(-3/0);  // -Infinity
console.log(typeof Infinity);  // number