프로그래밍 언어
-
[CS Study] 화살표 함수와 일반 함수프로그래밍 언어/JavaScript 2024. 1. 8. 00:10
개요 함수의 정의방식 일반 함수와의 차이점 함수의 정의 방식 함수의 정의 방식은 일반적으로 function keyword를 활용한 정의와 화살표 함수를 활용한 정의 2가지로 나뉘어진다 Function keyword를 활용한 정의 함수 선언식 함수를 선언하는 가장 기본적인 방법 호이스팅(선언을 최상단으로 끌어올리는 행위)이 가능하다 익명함수를 만들 수 없다 (함수의 이름이 필수) main() // 호이스팅으로 가능함 function main() { console.log('hello') } main() 함수 표현식 호이스팅이 되지 않는다 익명함수를 만들 수 있다 const main = function main() { console.log('hello') } // 네임드 함수 const main = funct..
-
[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() 내부에서만 참조할 수 있다. 이러한 규칙을 스코프라고 한다. 스코프가 필요한 이유) 의도치 않은 변수 값의 변조를 방지 (변수명의 충돌) 효율적인 메모리 관리 (코드 블럭 안의 참조값들은 코드가 실행될 때만 메모리에 할당 됨) 전역변..
-
[Typescript] why Typescript?프로그래밍 언어/TypeScript 2023. 12. 8. 16:21
개요 자바스크립트와 타입스크립트란? 타입스크립트를 선택한 이유 착각하기 쉬운 타입스크립트 기본개념 Javascript) 동적 웹페이지를 만들기 위한 프로그래밍 언어로써 웹페이지를 조작하고, 서버와 클라이언트 간 상호작용에 관한 일을 한다. 등장배경 : 정적인 초기웹사이트에서 동적으로 변함에 따라 등장하게 되었다 인터프리터 언어이지만 컴파일러가 내장되어 있어 실행 속도가 매우 빠르다. 객체기반의 스크립트 언어이지만 함수형과 객체 지향형 프로그밍을 모두 구현할 수 있다, Typescript) Javascript를 기반으로 정적 타입 문법을 추가한 프로그래밍 언어 컴파일 언어, 정적 타입 언어 : 동적인 Javascript는 런타임에서 오류를 발견할 수 있는 것에 반해 Typescript는 코드의 작성 단계에..
-
[Javascript] this 예약어프로그래밍 언어/JavaScript 2023. 12. 7. 08:56
개요 this의 정의 함수호출방식과 this 바인딩 결론 this의 정의 Javascript의 예약어로써 함수의 호출 방식에 따라 this에 바인딩되는 객체가 달라진다. 자신이 속한 객체 또는 자신이 생성할 인스턴스를 가리키는 자기 참조 변수 자신이 속한 객체 또는 자신이 생성할 인스턴스의 프로퍼티나 메서드를 참조할 수 있다 Javascript엔진에 의해 암묵적으로 생성 ( + 호출시 내부에 인자와 this가 전달된다) 일반적으로 객체의 메서드 내부 또는 생성자 함수 내부에서만 의미가 있다. (참조 변수이기때문에) 지역변수처럼 사용 가능 느낌상 객체 내부에서 사용하는 것을 많이 떠올리게 된다. value라는 값을 가지고 있는 객체에 foo라는 함수를 할당하려할 때 그 함수에서 value를 사용하려 할 때..