프로그래밍 언어/JavaScript
-
[CS Study] 스코프, 스코프체인프로그래밍 언어/JavaScript 2024. 1. 2. 09:18
개요 스코프 스코프 체인 스코프 식별자의 유효범위로 변수에 접근할 수 있는 범위를 말하며 참조 대상 식별자를 찾아내기 위한 규칙이다. var x = "global"; function foo() { var x = "function scope"; console.log(x); } foo(); // function scope console.log(x); // global 위와 같은 코드에서 전역변수인 x는 어디서든 참조할 수 있지만 foo() 내부에 선언된 지역변수 x는 foo() 내부에서만 참조할 수 있다. 이러한 규칙을 스코프라고 한다. 스코프가 필요한 이유) 의도치 않은 변수 값의 변조를 방지 (변수명의 충돌) 효율적인 메모리 관리 (코드 블럭 안의 참조값들은 코드가 실행될 때만 메모리에 할당 됨) 전역변..
-
[Javascript] this 예약어프로그래밍 언어/JavaScript 2023. 12. 7. 08:56
개요 this의 정의 함수호출방식과 this 바인딩 결론 this의 정의 Javascript의 예약어로써 함수의 호출 방식에 따라 this에 바인딩되는 객체가 달라진다. 자신이 속한 객체 또는 자신이 생성할 인스턴스를 가리키는 자기 참조 변수 자신이 속한 객체 또는 자신이 생성할 인스턴스의 프로퍼티나 메서드를 참조할 수 있다 Javascript엔진에 의해 암묵적으로 생성 ( + 호출시 내부에 인자와 this가 전달된다) 일반적으로 객체의 메서드 내부 또는 생성자 함수 내부에서만 의미가 있다. (참조 변수이기때문에) 지역변수처럼 사용 가능 느낌상 객체 내부에서 사용하는 것을 많이 떠올리게 된다. value라는 값을 가지고 있는 객체에 foo라는 함수를 할당하려할 때 그 함수에서 value를 사용하려 할 때..
-
[스파르타코딩클럽] Javascript 문법종합반 1~ 2주차프로그래밍 언어/JavaScript 2023. 6. 12. 15:43
1주차 1 주차는 기본적인 내용과 반복문 및 조건문에 대한 내용으로 강의자료를 참고하면서 복기시키면 될 법한 내용이 주를 이루고 있다. - 삼항연산자 let x = 10; let result = (x > 5) ? "크다" : "작다"; console.log(result); // "크다" - 타입연산자 console.log(typeof 123); // "number" console.log(typeof "123"); // "string" console.log(typeof true); // "boolean" console.log(typeof undefined); // "undefined" console.log(typeof null); // "object" console.log(typeof {}); // "ob..