const는 변수를 바꿀 수 없도록 한다.
const name = "hyunhee";
let은 const와 달리 변수값을 바꿀 수 있다.
let age = 21;
true, false, null, undefined가 있다.
변수를 선언하고 값을 저장하지 않을 경우 undefined이고 null을 저장하면 undefined가 아닌 null이다.
let isHuman;
console.log(isHuman);
// undefined
isHuman = null;
console.log(isHuman);
// null
여러 변수들을 담을 수 있다.
let month = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november"];
자바스크립트에서 인덱스는 0부터 시작한다.
console.log(month[3]);
// april
객체에 새로운 값을 추가하려면 push()를 사용한다.
month.push("december");
console.log(month);
// ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november"]
객체는 관련된 데이터와 함수의 집합이다.
다음은 책의 객체이다. {}를 이용한다.
const book = {
title: "리어 왕",
author: "셰익스피어",
}
객체 내에 프로퍼티에 접근하려면 .을 이용한다.
console.log(book);
// {title: "리어 왕", author: "셰익스피어"}
console.log(book.title);
// 리어 왕
객체에 프로퍼티를 추가하려면 다음과 같이 한다.
book.pages = 193;
console.log(book.pages);
// 193
객체의 프로퍼티 값을 변경하려면 변수처럼 값을 변경할 수 있다.
book.pages = 200;
console.log(book.pages);
// 200