Javascript
-
비동기 vs 동기Javascript 2023. 6. 28. 15:00
비동기함수 : 호출부에서 실행 결과를 기다리지 않아도 되는 함수 동기 함수 : 호출부에서 실행 결과가 리턴될 때까지 기다려야 하는 함수 비동기함수의 대표적예 : setTimeOut(), setInterval() ⭐이 두 함수를 사용한 뒤에는 반드시 clearTimeOut(), clearInterval()로 타이머 청소해라 (spa 개발시 이 부분이 메모리 누수로 이어질 수 있음) https://www.daleseo.com/js-timer/ 👉 비동기 함수 호출시 return을 사용해 결과값을 받으려는 경우 예상치 못한 순서로 코드가 진행될 수 있다. 👉 결과값을 통해 처리할 로직을 콜백함수로 넘기는 스타일로 진행해라 최근에는 프로젝트가 복잡해짐에 따라 콜백으로 비동기처리 하는 스타일 피함 👉 콜백함수의 ..
-
자바스크립트 특징Javascript 2023. 4. 27. 12:54
다른 부분을 신경쓰고 있던 나는 자바스크립트를 기억에서 삭제했다. 그래서 다시한다. 자바스크립트 자바스크립트란? 자바스크립트는 객체 기반의 스크립트 언어로, 웹의 동적 구현을 위해 사용되는 프로그래밍 언어이다. 👉 웹 개발, 서버 개발 등 다양하게 활용 가능하다. 특징 1. 자바스크립트는 객체 기반의 스크립트 언어다. 객체 : property(속성 - 이름, 값으로 구성)와 method(메소드-객체에 저장된 값이 함수일 때 메소드라 부른다)로 구성된 데이터 집합 2. 자바스크립트는 동적이며, 타입을 명시할 필요가 없는 인터프리터 언어다. 인터프리터 언어: 소스 코드를 별도의 컴파일 과정 없이, 실행 중 소스를 해석해 실행하는 언어 - 장점: 코드를 즉시 실행하고 수정할 때도 즉시 반영 가능해 개발 속도가..
-
스코프(scope)와 호이스팅(hoisting)Javascript 2023. 4. 10. 23:06
스코프(Scope) 변수의 유효범위. 선언한 변수가 영향을 미치는 범위를 의미함. 호이스팅(Hoisting) 인터프리터가 변수와 함수의 메모리 공간을 선언 전에 미리 할당하는 것 변수의 선언과 초기화를 분리 후, 선언만 코드의 최상단으로 옮기는 것 (자바스크립트는 초기화를 제외한 선언만 호이스팅한다.) → 함수나 변수 선언하기 전에 호출해도 에러가 발생하지 않음 *인터프리터 : 프로그래밍 언어의 소스 코드를 바로 실행하는 프로그램 var 재선언 O, 재할당(타입 변경도 가능) O / 함수 스코프 (또는 전역 스코프) 더보기 블록 기준으로 스코프가 생기지 않아, 코드블록 내에 변수를 선언했어도 해당 변수는 전역변수가 된다.var로 선언한 변수는 어디서든 참조할 수 있으나, 변수에 할당하기 전에는 값은 un..