Skip to content
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

Fe_JS #29

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Fe_JS #29

wants to merge 8 commits into from

Conversation

h-0y28
Copy link
Collaborator

@h-0y28 h-0y28 commented May 16, 2024

No description provided.

Comment on lines +12 to +36
## **Function 사용법**
- ex) ```js```
```js
// 함수 정의
function functionName(parameter1, parameter2) {
// 함수 내용
const result = parameter1 + parameter2;
return result; // 함수가 값 반환 가능 (Optional)
}

const argument1 = 3;
const argument2 = 5;

// 함수 호출
const returnValue = functionName(argument1, argument2);
console.log(returnValue); // 출력: 8
```

- JS에서 함수를 정의 하는 키워드
- 이름과 매개변수(parameter)를 가짐
- 중괄호 **`{}`** 내에 함수의 코드 작성
- 필요에 따라 값을 반환 가능
- 반환 값이 없는 경우 : **`undefined`** 반환
- 호출될 때 매개변수를 전달받아 실행
- 전달된 매개변수 : 함수 내에서 사용 가능

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javascript에서 function을 사용하는 방법은 regular function, arrow function으로 크게 2가지가 있는데,
arrow function에 대해서와 일반 regular function과의 차이점도 알아보면 좋을 것 같습니다!

hyojoo/Fe_JS.md Outdated
Comment on lines 5 to 8
- **`let`**
- <span style="color:green">블록 범위</span> 지역 **변수** 선언
- 값이 필요에 따라 변경 가능
- <span style="color:green">블록 범위</span> : **`{}`** 로 둘러싸인 범위

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let에 값이 변경이 되는 과정에 대해서 알아보면 좋을 것 같습니다.

hyojoo/Fe_JS.md Outdated
Comment on lines 1 to 8
## const와 let
- JS에서 변수를 선언하는 데 사용되는 키워드
- **`const`**
- 한 번 할당된 값을 **변경할 수 없는 상수**를 선언
- **`let`**
- <span style="color:green">블록 범위</span> 지역 **변수** 선언
- 값이 필요에 따라 변경 가능
- <span style="color:green">블록 범위</span> : **`{}`** 로 둘러싸인 범위
Copy link

@gjaegyun gjaegyun May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

js에서 변수는 hoisting이란 과정을 거치는데
js 중 hoisting에 대해서 알아보면 좋을 것 같습니다.

hyojoo/Fe_JS.md Outdated
---
## JavaScript의 호이스팅(Hoisting)
- **의미**
- 변수와 함수 선언이 실제 코드 **실행 전**에 해당 스코프의 **최상위로 끌어올려지는 것**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최상위로 끌어올려지는 것 <- 확실한가요..?

Comment on lines +52 to +53
- 변수와 함수 선언이 실제 코드 **실행 전**에 해당 스코프의 **최상위로 끌어올려지는 것처럼** 동작하는 작동 방식
- 변수와 함수 선언이 해당 스코프의 상단으로 끌어올려지는 것처럼 동작하는 자바스크립트의 작동 방식

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럼 실제로 코드가 상단으로 이동하는 것은 아닌데, 어떤식으로 동작하나요?

hyojoo/Fe_JS.md Outdated
Comment on lines 55 to 58
- **변수 호이스팅**
- `var`로 선언된 변수는 호이스팅 됨
- 초기화는 원래 위치에서 이루어져 초기화 전에는 `undefined` 값을 가짐
- `let`과 `const`로 선언된 변수도 호이스팅되지만, 초기화 전 접근 시 `ReferenceError`가 발생

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var, let, const 모두 hoisting이 되지만 왜 var는 undefined, let, const는 referenceError가 발생하나요?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hoisting 관련해서 알아보니 잘 설명이 되어있는 글이 있네요
읽어보시면 도움이 될 것 같습니다!
https://velog.io/@1nthek/JavaScript-%EB%B3%80%EC%88%98%EC%99%80-%ED%95%A8%EC%88%98-%ED%98%B8%EC%9D%B4%EC%8A%A4%ED%8C%85Hoisting%EC%97%90-%EB%8C%80%ED%95%B4-%EC%95%8C%EC%95%84%EB%B3%B4%EC%9E%90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants