본문 바로가기
JavaScript/Youtube

JavaScript/freeCodeCamp - Full Course for Beginners 59:30~1:59:16

by SKim입니다 2020. 6. 15.

youtu.be/PkZNo7MFNFg?t=3570

함수 안에서 declare된 변수와 parameter들은  local sope를 가진다.

= 그 함수 안에서만 보인다.

 

 

 

똑같은 이름의 local 변수와 global 변수가 존재할 수 있다.

이런 경우에 local 변수가 우선한다.

 

 

 

함수는 return statement를 가질 수 있지만, 항상 그래야 하는 것은 아니다.

 

변수 sum은 함수 전에 define되었으므로 global 변수이다.

sum은 3이 되지만, return이 없으므로 3을 출력하지는 않는다.

= return value is undefined.

 

return된 value를 variable로 assgin하기

 

 

computer science에서 queue란:

an abstract data structure where items are kept in order.

new items can be added to the back of the queue

and old items are taken off from the front of the queue

 

nextInLine 함수를 이용해서 queue처럼 만들어보자.

1:05:53~1:08:41

????

 

 

true나 false에 quotation marks를 사용하지 않는다.

 

==(equality operator)을 써야 한다.

=은 assignment operator이다.

 

===은 strict equality operator이다.

차이:

Equality operator(==) attempts to convert both values being compared to a common type.

Strict equality operator(===) does not do the type conversion.

true

false

 

여기서 ===를 ==로 바꾸면 둘다 true가 된다.

== → equal

=== → not equal

 

 

 

 

inequality operator - basically the opposite of the Equality operator

 

 

 

두 가지가 동시에 true인지 check

 

 

&& = and

 

|| = or

 

when an if steam is true,

normally the block of code right after the if statement

will be evaluated.

 

if it's not true,

nothing happens.

 

but with an else statement,

an alternate block of code can be executed

when it's not true.

 

if you have multiple conditions

that need to be addressed

you can use else if statements.

 

if else statement에서는 순서가 매우 중요하다.

 

3열이랑 5열을 바꿔야 한다.

 

In the game of golf,
each hole has a par
which means the average number of strokes
you're supposed to use
to get the ball into the hole.

So depending on
how far above or below par your strokes are,
there's a different nickname.

 

par과 strokes를 pass in하면 nickname을 return해주는 함수를 만들어보자.

 

오타: name → names

 

 

chained else if statement 대신에 switch statement를 쓸 수 있다.

 

a switch statement test a value
and can have many case statements
which define various possible values.

 

 

 

 

 

 

만약 val이 1이면(===)

 

Break means
that we're at the end of that case statement
and once you break it
it just goes to the end of the switch statement.

It doesn't evaluate anything else
in the switch statement.

 

---

 

If you don't have a break statement,
it will just run through to the next case statement automatically.

So, if the case was 1,
and you did not have a break here,

first it would set the answer to alpha
and then it would set the answer to beta

It would just skip over right to the next case.

Default 옵션은 if statement의 else같은 것이다.

 

sometimes you want a switch statement
where multiple inputs give the same output.

- break statement를 생략하는 것으로 가능하다.

 

break가 없으므로 자동으로 다음 것으로 넘어간다.

return을 사용해서 중간에 끝낼 수 있다.

(you can return early from a function
with the return statement.)

블랙잭 카드 카운팅 함수

when you see a low card,
that count goes up

and when you see a high card,
that count goes down

and if it's a middle value card,
the count stays the same

and then when the count is positive,
the player should bet high

and when the count is zero or negative,
the player should bet low

 

switch 사용

 

 

holdbet 함수는

ternary operator를 쓰는 것이 제일 좋지만,

아직 안 배웠으니

objects are similar to arrays
except that instead of using indexes
to access data you use properties.

 

객체 { }

name, legs, tails, friends - properties

camper, 4, 1 등 - value

 

the properties can be strings
they can be numbers
they can be arrays
they can be any data type in JavaScript

 

객체의 프로퍼티에 접근하는 데는 두 가지의 주요한 방법이 있다.

(1) dot notation

(2) bracket notation은 아무 때나 쓸 수 있지만,

빈 칸이 있을 때는 꼭 써야 한다.

 

bracket notation can also be used to
look up object properties
using variables.

 

we can use dot notation
to update object properties

 

 dot / bracket notation 이용

 

 

 

objects can be thought of
as a key value storage
like a dictionary.

↓ 똑같다.

 

 

you can check
if an object has a property
with the hasOwnProperty method

객체이름.hasOwnProperty(체크할 프로퍼티 이름)

→ True/False 출력

 

 

댓글