본문 바로가기
JavaScript/Youtube

JavaScript/freeCodeCamp - Full Course for Beginners 1:59:16~2:36:57

by SKim입니다 2020. 6. 15.

a JavaScript object is a way to store flexible data
so you can store
strings, numbers and arrays and even other objects.

 

 

myMusic이라는 array 안에 object가 있다.

이것은 json과 비슷하다.

 

maps를 get하기

띄어쓰기 있으니까 [" "]

pine

코딩 챌린지

 

 

 

31행의 함수를 만들어보자.

 

if we have an empty string for the value,
it should just completely delete that property

also if we have the property of tracks,
and then we have a value

instead of updating the whole tracks here
with what we put in.

 

comment: Keep a copy of the collection for tests.

 

JSON.parse(JSON.stringify(collection));

This is just a fancy way in JavaScript
to make a copy of the object.

Remember, in our function,
we are going to be changing the collection - object.
But we want to have a copy of the original object
before anything was changed.

 

id: 2548

prop: album

value: Slippery when Wet

 

The next condition we have to look for
is if the property is tracks.

Because for most properties,
we're just going to override that property
with the value passed into the function.

But if the property is tracks,
we are going to push on to the end of the array.

 

 

If the tracks property is empty,
we need to create it.

 

It's going to
either equal itself if it exists
or if it doesn't exist we're going to create it.

 

 

if this already exists,
we're gonna set to equal itself

but if itself doesn't exist,
we'll just set it to equal an empty array.

 

 

so that's just a way to create that property
if it doesn't already exist

 

---


so now that we know it exists
we can just push the value
to the end of the array

If the values isn't blank
and the property isn't tracks,

then we just push the value onto the property
then we just set the property to equal the value

 

 

 

 

a for-loop is the most common type of loop in JavaScript.

 

 

 

 

< how a do-while loop is different than a while loop >
while loop: first checks the condition
before it runs any code within the loop

do-while loop: will always run
at least one time
and then it will check the condition.

 

 

코딩 챌린지

if the name that's passed in
does not correspond to any context,
then our functions should return no such contact

if there's no property
it should return no such property

 

---

 

a fancy way in JavaScript of saying
use this value if it exists
but otherwise use a different value
is to use the 'or operator'.

so we'll say return contact[i][prop]
or if it doesn't exist
we're gonna return no such property.

 

 

 

 

0 ≤ x < 1

 

0 ≤ x < 20

→ 1, 2, ... , 18, 19

 

parseInt function
- takes a string and returns an integer 

 

if the string cannot be converted into an integer
it returns NaN for not a number

 

the radix specifies
the base of the number
in the string

진법

 

we'll have a second argument
after the comma
which is going to be the number 2.

so the default of base 10 will be passing it as base 2
so the computer knows that this is a binary number.

 

I love the ternary operator
it's like a one-line if-else expression

 

 

4행과 같이 쓴다.

6행과 같은 의미이므로 이렇게 쓸 일은 없지만

이런 식으로 쓴다.

 

장점: you can nest them within each other
which gives them even more power.

 

---

 

it's going to return the string "positive",
if this number is positive

"negative",
if the number is negative or zero.

and we're gonna use a nested conditional operator.

 

after 첫번째 :,
we have an entire ternary operator

so if this is true
we just return positive

if it's false then we do everything here,
which is another ternary operator (첫번째 : 뒤)
where it checks if this is true

and if that's true
we return negative and if it's false
we to return zero

댓글