본문 바로가기

전체글

(45)
[Javascript] When to use for and when to use while 굉장히 축약해서 말하자면 loop를 돌려야 하는 횟수가 정해져 있는 경우 for loop를 돌려야 하는 횟수가 정해져 있지 않은 경우(특정 조건을 만족할 때까지 실행) while이다. const cards = ['diamond', 'spade', 'heart', 'club']; // Write your code below let currentCard; while (currentCard !== 'spade') { currentCard = cards[Math.floor(Math.random() * 4)]; console.log(currentCard); } 근데 지금 그게 문제가 아니다 이 코드가 이해가 안 되기 시작했다 천천히 보자... 우선 card array가 있고 밑에 let으로 currentCard ..
[Javascript] Pass-by-Reference라는 용어를 처음 보았다. array를 배우다가 pass by reference라는 개념이 나왔는데 읽어 봐도 도통 이해가 안 되었다. array가 함수 안에서 변경될 경우 함수 바깥에서도 그대로 변경된다 -> You might also see this concept explained as pass-by-reference... 라고 하는데 pass-by-reference가 그래서 뭘까? 우리가 함수에 던져 주는 값은 variable memory가 stored 되어 있는 곳에 대한 reference고, 이 reference가 memory를 바꾼다. 이런 설명 같은데 음... 메모리가 어떤 개념인지 잘 모르겠어서 약간 감이 안 오는 것 같다. 구글링을 해 보다 보니, pass by reference를 다른 개념과 비교해서 보아야 한다..
[Javascript] scope 이해가 안 되는 게 한 개 있어서... const logVisibleLightWaves = () => { let lightWaves = 'Moonlight'; let region = 'The Arctic'; // Add if statement here: if(region === 'The Arctic') { let lightWaves = 'Northern Lights'; console.log(lightWaves) } console.log(lightWaves); }; logVisibleLightWaves(); // prints Northern Lights and Moonlight 아 또 블로그에 글을 쓰니 시작하니까 바로 이해가 됐다ㅎㅎ 신기하네 함수 안에 console.log가 두 번 잇고만! lightwave를 출력하는데 1. region이 ..
[Javascript] Scope Pollution이라는 굉장히 흥미로운 용어 발견 scope pollution이라는 용어 안에 pollution이 있어서 눈길을 확 사로잡았다ㅋㅋㅋㅋ scope pollution이 그래서 뭐냐! 나는 용어만 보고 예상했을 때 scope의 범위를 적절하게 설정하지 않아 부정적인 방향으로 상호 교섭이 일어나는 것이라고 생각을 했는데 비슷하게 맞았다. global scope에 되도록 variable을 declare? 하지 않는 게 좋다고 설명이 되어 있다(출처codecademy) let num = 50; const logNum = () => { num = 100; // Take note of this line of code console.log(num); }; logNum(); // Prints 100 console.log(num); // Prints 100..
[Javascript] Mysterious Undefined function logVisibleLightWaves() { const lightWaves = 'Moonlight'; console.log(lightWaves); } console.log(logVisibleLightWaves()); // prints: Moonlight // prints: undefined 이렇게 undefined가 뜰 때면 참 이유가 궁금하다. 내가 어떤 변수에 값을 할당하지 않고 호출했다는 뜻인데, 여기서 내가 호출하지 않은 게 있나? 아 갑자기 이해함!!!!!!!!!!! 역시 타이핑 하면서 공부하면 머리가 잘 돌아간다. 아까 글 적었던 것과 같은 이유인데, console.log(logVisibleLightWaves()); 는 console.log(console.log(lightWav..
[Javascript] block과 global scope 퇴근 개빨리하고 코딩 공부하는 중 자율근무제 짱이다 진짜 간단하게, {} 이걸 블록이라고 한다. function test(num) { const A return A } 극단적으로 간단한 예를 들어 보면...(맞게 썼는지도 모르겠음. return const A라고 썼어도 맞았으려나?) const A는 {}, block 안에서 선언된 variable이다. global scope에 대해서 논하기 전에 scope는 뭘까? Scope is the context in which our variables are declared. variable이 선언되는 범위? context를 어떻게 옮기면 좋을지 모르겠네... 그러니까 변수가 선언되고 context 안에서 의미를 가질 수 있는 범위를 뜻하는 듯하다. block의 ..
[Git] 깃 깃ㄱ 깃 깃 깃 깃이고 뭐고 공부하다 피곤해서 죽을 것 같아서 미니쉘 다섯 개로 당충전하고 다시 컴퓨터 앞에 앉았다... 아 오늘 왜 이렇게 힘들지!!!! 눈이 막 감기네 그래도 이제 깃이 뭔지 좀 알 것 같다. 1. working directory에서 맘대로 자유롭게 수정한 다음에 save 2. 그러면 staging area에 보낼 수 있는데, 이건 최종 commit까지 change status가 저장되는 곳이라고 이해 3. 최종 commit 하면 영원히 바꿀 수 없게 repo에 깃 버전이 저장됨 ~전체 과정~ working directory에서 수정한 다음 git add로 staging area에 보냄 잘 보내졌는지 확인하려면 git status -> modified 뜨는지 확인 modified 떴으면 잘 add가 ..
[Git] Git의 전체적인 흐름을 알아보쟈 According to the course, there're three parts of the Git: Part 1: A Working Directory. Git init을 하면 working directory에 진입할 수 있다('진입'이라는 표현이 맞는지는 모르겠음) working directory에서 할 수 있는 것들은 Addtion Deletion Modification 한 마디로 파일을 어떤 방식으로든 수정할 수 있다는 것 같다(아마도). 그리고 working directory에서 git add(뭔지 모름)라는 걸 하면 Part 2: Staging Area Here comes the 'staging area', where I can list all the changes I made to the w..