[Day2] Javascript - Notation

ShiHoon Yoon·2020년 7월 20일
0

Object 값 불러오기

example)

var car = {
company: 'BMW',
color: 'black',
'model': 'M3',
'manufacture year':2019

.dot notation (점표기법)

object.property;

car.company; //'BMW'
car.color; //'black'

색깔을 바꾸고 싶으면

car.company = 'Tesla';
car.color = 'red';

하지만 'model', 'manufacture year'를 불렀을 경우 error가 된다.

1) ' ' object에 쓸 수 없다
2) manufature year처럼 space가 들어가면 안된다.

이러할 경우 braket notation을 사용한다.

bracket notation (괄호표기법)

car['company']; // 'BMW'
car['color']; // 'black'

.dot notation에서 error가 떳던것들도

car['model']; // 'M3'
car['manufacture year']; // 2019

그럼...dot notation을 더 많이 사용하는 이유는...간단하다

빠르고 쉬워서 ㅎㅎ


profile
Entrepreneurs Should Learn to Code

2개의 댓글

comment-user-thumbnail
2020년 7월 20일

오 점표 표기법은 처음 알았네요! 😮 하나 배워갑니다!

1개의 답글