프로그래밍 언어
-
[Javascript] 메모리 할당프로그래밍 언어/JavaScript 2024. 1. 18. 18:39
메모리 할당 Javascript는 객체가 생성되었을 때 자동으로 메모리를 할당하고 필요하지 않으면 자동으로 해제(가비지 컬렉션)하는 자동 메모리 관리가 가능하다. 이러한 메모리 관리는 잠재적 혼란의 원인이 되기도 한다. 메모리 생존주기 필요할 때 할당 할당된 메모리 사용 (읽기, 쓰기) 필요 없으면 해제 자바스크립트는 일련의 과정이 암묵적으로 작동한다.(고수준 언어) 필요없을 때는 언제인가? 저수준의 언어(C언어)에서는 개발자가 직접 결정하고 해제하는 방식이지만 자바스크립트는 자동으로 하기에 필요없어진 시기를 알아내기 어렵다. 그렇기에 자동 메모리 관리 방법을 사용하는 가비지 콜렉터를 사용하여 메모리를 관리하는 것이 궁극적인 방법은 아니다 메모리의 필요 유무는 비결정적 문제이기 때문이다.
-
[Javascript] 즉시 실행 함수 IIFE프로그래밍 언어/JavaScript 2024. 1. 18. 18:20
즉시 실행 함수란? (IIFE) 정의되자마자 즉시 실행되는 함수로 소괄호로 함수를 감사 실행하는 문법이다. (function () { console.log("IIFE"); })(); // 화살표 함수로도 사용 가능하다 (() => { console.log("IIFE"); })(); 선언과 동시에 출력한다는 것을 알 수 있다. 기명 함수로 사용할 수 있지만 선언과 동시에 호출되어 반환되어 재사용 할 수 없기에 이름을 지어주는 것이 의미가 없다. 특징 필요없는 전역 변수의 생성을 줄일 수 있다 private한 변수를 만들 수 있다. 활용예제 단 한번의 사용이 필요한 함수 let isAdult; (function init(age) { let currentAge = age; if (age >= 20) { isA..
-
[Javascript] strict mode프로그래밍 언어/JavaScript 2024. 1. 18. 18:05
개요 엄격모드란? 엄격 모드 (strict mode) ES5의 등장으로 인해 기존에 사용하던 기능 중 일부가 변경되었다. 이에 따라서 기존까지 사용하던 코드에서 문제가 발생할 수 있기에 이러한 변경된 사항들을 적용하려면 'use strict'라는 특별한 지시자를 이용해서 엄격 모드를 활성화 했을 때만 이 변경사항이 활성화되게 해놓았다. 사용방법 'use strict'; ... 반드시 최상단에 위치시켜 활성화를 시켜야 하며 보다 상단에 위치한다면 적용되지 않는다. 함수 안에서도 사용이 가능하다 발생하는 제약 조건 전역 변수를 허용하지 않으며 선언 시 오류가 발생 변수 이름 선인 및 사용시 var를 누락하면 오류 발생 값 할당 실패 시 오류 발생 (NaN = 1) 삭제할 수 없는 속성 삭제 시 오류 발생 (..
-
[Javascript] Blocking / Non-Blocking vs Sync / Async프로그래밍 언어/JavaScript 2024. 1. 17. 23:40
개요 배우는 목적 Blocking / Non-Blocking Sync / Async 정리 배우는 목적 기본적으로 블록과 동기가 같은 의미인가에 대해서 아니라고 확실히 대답할 수 있을만큼의 지식을 기르는 것에 있다. 자칫 오해할 수 있는 개념이기에 조금 정립하고 넘어가자. Blocking , Non-Blocking 제어권이 있는지 없는지에 따라서 Blocking과 Non-Blocking으로 나뉜다. Blocking 자신의 작업을 진행하다가 다른 주체의 작업이 시작되면 다른 작업이 끝날 때까지 기다렸다가 자신의 작업을 시작하는 것 즉, 호출된 함수는 자신이 할 일을 모두 마칠때까지 제어권을 계속 가지고 있으며 호출한 함수에게 바로 돌려주지 않는 상황 Non-Blocking 다른 주체의 작업에 관련 없이 자신..