분류 전체보기
-
[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 다른 주체의 작업에 관련 없이 자신..
-
[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..