7/6 일지

박성운·2022년 7월 10일
0

-조건문(if)-
if(a>1){
a 가 1보다 크다
}else if(a===1){
a와 1이 같다.
]
else{
a 가 1 보다 작다.
}

조건문에서 조건식이 일치할 경우 (=true)로 실핻된다.
조건식이 일치하지 않을 경우 (=false)에는 예외 else가 실행된다.

else if를 추가로 적용하면 반드시 ()에 조건식을 넣어야 한다.

-switch문-
사용방법->
const day ="월요일"

switch(day){
case "월요일":
"월요일 입니다."
break;
case "화요일"
"화요일 입니다."
default;
day + "입니다.'
}
break를 사용해야 한다. 그래야 어떠한 케이스에 걸리지 않는다.
만약 default를 사용하면 break는 쓰지 않아도 된다.

오늘 알고리즘 시간에 봤던 문제중 하나입니다.
문제 설명

입력되는 달(month)에 따라 각 달에 며칠이 있는지 보여주는 함수를 만들려고 합니다.

각 조건에 해당하는 알맞은 값을 입력해주세요.

입력 인자

  • month는 1~12의 숫자

주의 사항

  • || 연산자가 필요합니다.
  • 2월은 28일로 계산합니다.

->두가지 방법으로 답을 낼 수 있다.
1)
function days(month) {
if(month===1|| month ===3||month ===5||month ===7||month ===8||month ===10||month ===12) {
return "31"
}
if(month===4||month===6||month===9||month===11){
return "30"
}
if(month===2){
return "28"
}
}
days(1)
-> 여기서는 if 문을 사용 하였다.
2)
const monthList = {
1 : 31,
2 : 28,
3 : 31,
4 : 30,
5 : 31,
6 : 30,
7 : 31,
8 : 31,
9 : 30,
10: 31,
11: 30,
12: 31,
}

function days(month)
{
return monthList[month]

}
->여기서는 객체를 사용했다.

  • 배열 복사-
    profile1 -> profile2 let profile5={...profile} <- 얕은복사 let profile5 = {
    ...profile,
    hobby:{...profile.hobby}

}

profile
{name: '영희', age: 12, school: '다람쥐초등학교', hobby: {…}}
age: 12
hobby: {hobby1: '잠자기', hobby2: '자전거'}
name: "영희"
school: "다람쥐초등학교"
[[Prototype]]: Object
~>
JSON.parse(JSON.stringify(profile))
{name: '영희', age: 12, school: '다람쥐초등학교', hobby: {…}}
age: 12
hobby: {hobby1: '잠자기', hobby2: '자전거'}
name: "영희"
school: "다람쥐초등학교"
[[Prototype]]: Object
->깊은 복사

Ex)
const child1 ={
name:"철수",
age:13,
school:"다람쥐초등학교"}

child1.name.last="김"
'김'
child1.name.last="철수"
'철수'
~>
child1
{name: {…}, age: 13, school: '다람쥐초등학교'}
age: 13
name: {first: '김', last: '철수'}
school: "다람쥐초등학교"
[[Prototype]]: Object
~>
const child2=JSON.parse(JSON.stringify(child1))
~>
child2
{name: {…}, age: 13, school: '다람쥐초등학교'}
age: 13
name: {first: '김', last: '철수'}
school: "다람쥐초등학교"
[[Prototype]]: Object
~>
child2.name={first:"최",last:"영희"}
~>
child2
{name: {…}, age: 13, school: '다람쥐초등학교'}
age: 13
name: {first: '최', last: '영희'}
school: "다람쥐초등학교"
[[Prototype]]: Object

const myprofile = Object.freeze(profile)->안전하게 파일 작성 가능.

Ex)
const child={
name:"tom",
age:8,
school:"elementary school",
money: 2000,
hobby:"swim"
}

const {money,hobby,...rest} = child

rest=
{
name: 'tom',
age: 8,
school: 'elementary school'
}

Grapha-API 는 필요한거만 쓸 수 있다.

-JSON-
(javascript Object notion)
(응답) 헤더
(요청) 헤더
-CRUD-
create read update delete

axios

0개의 댓글