-
Notifications
You must be signed in to change notification settings - Fork 3
호프가 이 글을 모두에게 바칩니다. 데이터 타입 정리~🥷 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
호프 안녕하세요!
피곤하실텐데 정리하느라 고생하셨습니다~
몇 가지 궁금한 점 코멘트 남겼으니 확인해주세요!
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호 심벌 테이블이란게 있군요!
심벌 테이블이 어떤 방식으로 데이터를 관리하는지 설명해주실 수 있나요?
구조도 궁금하네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일단 심볼테이블이란 것 자체는 자료구조 이름이라구 하네요. '키-값'으로 이루어진 해시테이블을 심볼테이블 이라구 한대요!
따라서 심볼테이블은 자바스크립트에만 있는게 아니라, 컴파일러 또는 인터프리터 같은 언어 변환기에서 사용되는 자료구조라고 해요!
그러면..심볼테이블이 왜 필요하냐하면, 식별자(변수명)과 데이터의 주소,타입,스코프 등을 저장하기 위해서라구 합니다.
즉, 변수가 선언된다고 하면 테이블에 변수의 타입과 이름, 주소 등을 저장하게 되는거죠.
그러면 이를 또 왜 저장해야하냐? 라고 반문하실 수 있을텐데, 그러면 아래와 같은 이유 때문이라고 합니다~
1. 의미 분석 : 테이블에 저장된 정보를 사용하여 식과 할당이 시멘틱(의미)적으로 올바른지 확인(유형 검사) 할 수 있습니다.
2. 중간 코드 생성: 할당되는 런타임의 양과 유형을 알기 위한 심벌 테이블을 참조하고 임시 변수 정보를 추가합니다.
3. 코드 최적화: 최적화를 위해 심벌 테이블에 있는 정보를 사용합니다.
4. 대상 코드 생성: 테이블에 있는 식별자의 주소 정보를 사용하여 코드를 생성합니다.
따라서 자바스크립트의 심볼테이블 구조는 '식별자(key) - 값의 주소/데이터 타입/ 스코프 등(value)'이 되고, 심벌 테이블에 저장된 정보를 통해 인터프리터가 자바스크립트 코드를 해석한다고 볼 수 있을 것 같아요.
심벌테이블의 구조는 그냥 일반적인 해시테이블과 같다고 생각하시면 될 것 같아요! 대신 key 가 식별자, value 가 위에서 말했듯이 값의 주소/데이터 타입/ 스코프 등이 되겠죠?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그럼 간단히 말해서 자바스크립트에서 사용하는 각종 정보들을 키 - 값으로 매칭해서 저장해두는 자료구조(해시테이블)라고 이해하면 될까요?
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이쓴 값
오타 있어요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니당 호호
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메모리 주소를 직접적으로 제어해서 발생할 수 있는 치명적인 오류의 예시를 알 수 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오..좋은 질문!
만약에 실수로 개발자가 운영체제가 사용하고 있는 값을 변경한다면 어떤 일이 벌어질까요?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 역질문인가요? 다른 프로세스가 사용하고 있는 메모리 영역을 침범하면 해당 프로세스의 데이터가 손상되거나 정상 동작하지 않을 수 있겠죠?
질문 : 웹 브라우저에서 작동하는 자바스크립트도 운영체제의 메모리 영역과 관련이 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
크롬을 기준으로 설명드릴게요. 크롬은 멀티 프로세스 브라우저입니다. 즉, 하나의 탭 = 하나의 프로세스로 실행되구요, 그러면 당연히 프로세스는 메모리를 사용하게 됩니다!
그러면 자바스크립트는 브라우저 위에서 실행이 되니까 만약 메모리 주소를 직접적으로 제어 할 수 있다면, 개발자가 브라우저 프로세스의 메모리 영역을 침범하게 될수도 있습니다.
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
데이터 환
오타!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정신을 어따 빼먹고 왔는지~~
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자바스크립트의 가비지 컬렉팅은 어떤 상황에서 이루어지나요?
다른 언어의 가비지 컬렉팅과 차이가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른언어..아마도 C같은 저수준 언어에서는, 메모리 해제를 하기 위해서는 직접 메모리 해제를 호출해야한다고 알고있어요!
반면 자바스크립트는 객체가 생성되었을 때 자동으로 메모리를 할당하고 쓸모 없어졌을 때 자동으로 해제합니다!
그러면 대체 어떻게 해당 메모리가 더이상 쓸모없어졌다는 것을 알게될까요?
자바스크립트와 같은 고수준 언어들은 가비지콜렉터 (GC) 를 사용한다고 합니다. 가비지 콜렉터의 목적은 메모리 할당을 추적하고 할당된 메모리 블록이 더 이상 필요하지 않게 되었는지 판단하고 회수하는거죠.
그러면 가비지컬렉터는 어떻게 동작할까요?
- 가비지 콜렉션 알고리즘의 핵심 개념은 '참조'라고합니다. A라는 메모리를 통해 (명시적이든 암시적이든) B라는 메모리에 접근할 수 있다면 "B는 A에 참조된다" 라고 한다고해요.
- 따라서 '참조 카운팅 알고리즘'을 사용하는데요, 이 알고리즘은 어떤 객체를 참조하는 객체가 하나도 없는 경우 해당 객체를 '가비지'라고 부른다고 하고, 이를 회수하겠죠?
크..민초덕분에 딥하게 공부하네요
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null의 데이터 타입은 object로 알고 있는데요!
'객체가 아니다'가 무슨 의미인지 알 수 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자바스크립트는 일단 자바에서 값을 원시값과 객체로 나눈 접근법을 빌려왔고, 자바에서 '객체가 아님'을 나타내는 값인 null 을 도입해왔다고 합니다.
typeof null 이 object 인거는 자바스크립트 자체의 버그라구 합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
형식상으로는 object이지만 의미상으로는 object가 아니다라는 의미군요! 역설적인 버그네요~
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
비어있는 값이 어떤건가요? null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
만약 프로그래머가 아래와 같이 명시적으로 null을 삽이한 경우 null 도 순회를 돌게됩니다. undefined 도 마찬가지구요!
const arr = [null,null];
arr.forEach((_,idx)=>{
console.log(idx)
})
// 0, 1 출력
여기서 말하는 '비어있는 값'은 애초에 배열에 할당 조차 되지 않은 값을 의미하는게 아닐까 싶네요~!
즉 undefined 나 null 을 할당하면, 배열이 인덱스를 이름으로 지정하고 데이터의 주솟값을 저장하는 동작을 하게 되는거죠 ?
따라서, 자바스크립트가 반환해주는 undefined는 문자 그대로의 값이 없음을 나타내는 거고,
프로그래머가 명시적으로 선언해주는 undefined 는 실존하는 값이 된다! 이 말이죠~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 호프~ 눈이 막 감기는데 호프의 PR 리뷰 남겨야하니 정신 붙들고 남기고 있습니다..
역시 호무위키답게 처음부터 정리를 잘 해주셨더라고요! 보면서 오호, 오호! 했습니다 🙃
간단하게 읽으면서 궁금했던 점을 질문으로 남겨봤어요~ 편하실 때 답변해주세요 :)
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그러면 같은 값일 때는 같은 주솟값을 가지고 있는 것이라는 의미가 될 것 같은데, 맞나요?
예를 들면
const str1 = 'hope';
const str2 = 'hope';
에서 str1과 str2는 서로 같은 주솟값을 가지고 있는 것일까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 맞습니다!
두번째 구문에서 str2에 'hope'이란 문자열을 할당할 때, 먼저 메모리의 데이터 영역에 'hope'이라는 문자열이 저장되었는지 찾아보고 있다면 해당 메모리를 저장한다구 해요!
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왜 1바이트는 8비트인가요? 8비트가 적정한 공간이라는 의미일까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정말 생각지도 못했던 질문입니다!!
찾아봤어요.
이유는 컴퓨터 구조가 영문권인 곳에서 발전했기 때문이라고 합니다.
0101010 로 이루어진 전자신호를 사람이 인식할 수 있는 문자로 저장을 했어야 했는데,
이런 문자를 표현하는 코드들의 숫자가 7bit ~8bit 으로 충분했기 때문이라고 하네요?
(ASCII : 제어문자(32개), 출력가능문자(영소문자, 영대문자, 숫자, 기타 기호, parity bit 등등)
이에 따라서 1바이트에 에 문자 1개를 저장할 수 있는 8비트 구조가 된 것이라고 합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와 대단합니다!! ㅋㅋ
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
각 데이터 타입은 할당되는 메모리 용량이 다른데, 자바스크립트 엔진은 컴파일 시가 아니라 런타임 시 타입을 추론한다고 알고 있어요! 이 메모리 용량도 런타임 시에 타입에 맞게 할당되는 걸까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 질문 너무 좋아서 디스커션에서 답해드릴게요 슝~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
호프~ 호프위키 맞네요!! ㅋㅋ
답변을 보고 감탄했습니다 ㅎㅎ 배우고 갑니다 😆
호프/01-데이터-타입.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와 대단합니다!! ㅋㅋ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
호프 답변과 정리 모두 정말 수고 많으셨습니다~! 퀄리티가 너무 좋아서 보면서 많이 배웠어요 😆 수고하셨습니다 👍
🥷