Section 9-2: Data Structures, Modern Operators and Strings

Jayden·2021년 1월 18일

JavaScript Studying

목록 보기
5/11

110. Looping Arrays: The for-of Loop

for ( const item of menu) console.log(item);


111. Enhanced Object Literals


So before ES6, we would have to write opening hours so that's the property name that we want and then set it equal to opening hours.

but it can become annoying is that this property name is exactly the same as the variable name from which we're getting this new object, right?

-> And so with enhanced object literals you don't need to write this

-> we can write it in an easier way which is to get rid of this function, even of the semicolon and then just like this. orderDelibery가 기존 방식, order가 새 ES6 way


112. Optional Chaining (?.)

So only if Monday exists, then this open property will be read from there.

All right? But if not, then immediately undefined will be returned.

And exists here actually means the nullish concept that we already talked before.

So, a property exists if it's not null and not undefined.

Okay?

So if it's zero or the empty string, then it still exists of course.

So if we try this now, then we get undefined.

-> restaurant.openingHours[day] 를 위에처럼 바꾼것. undefined는 closed로 바꾸려면
|| 'closed'; 추가

하지만 토요일에 값이 0이라서 closed라고 뜸 why?
And the problem is that the restaurant opens at zero. And so here we have the same problem as before where zero is a falsy value.

해결하기위해서 nullish 사용 which is to use the nullish coalescing operator.

??사용하여 undefined or null 이면 실행( 0은 falsy value라 undefined or null이 아니기때문에 그대로 출력)

line 76. users[0]이 있으면 users[0].name을 실행, ?? 없으면 User array empty
users=[]로 비워놨으니 empty가 출력됨

users[0]이 있으니 name 가져와서 Jonas 출력. if문보다 훨씩 효율적.

113. Looping Objects: Object Keys, Values, and Entriesa


key and value 가져옴

destructure value

profile
G'day mate!

0개의 댓글