







자바스크립트 객체는 이름과 값으로 구성된 순서가 없는 속성들의 리스트.
함수도 객체이기 때문에 속성 값으로 함수가 될 수 있으며, 이를 메서드라고 부른다.
객체의 속성이나 메서드에 접근할 때는 점 표기법(dot notation)을 사용한다.
자주 사용되는 내장 객체에는 Object, Function, Boolean, Error, Number, Math, Date, String, RegExp 등
Array : 배열을 다루기 위한 객체로, 배열의 메서드와 속성을 제공합니다.
** 예시 method : push(), pop(), forEach(), map()
Date : 날짜와 시간을 처리하는 객체입니다. 현재 날짜와 시간을 가져오거나, 특정 날짜를 계산하는 데 사용됩니다.
** 예시 method : getDate(), getFullYear(), toLocaleDateString()
RegExp (정규 표현식): 문자열 내에서 특정 패턴을 찾거나 대체하는 데 사용됩니다.
@ 예시 method : test(), exec()
@ RegExp 플래그:
RegExp에서 자주 사용되는 플래그는 다음과 같습니다:
g: 전역 검색. 일치하는 모든 항목을 찾습니다.
i: 대소문자를 구분하지 않고 검색합니다.
m: 여러 줄 검색. 여러 줄에서 시작 또는 끝을 확인합니다.
u: 유니코드 모드로 검색합니다.
// 이메일 형식을 확인하는 정규 표현식
let emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
let email = "example@example.com";
console.log(emailPattern.test(email)); // true
email = "invalid-email";
console.log(emailPattern.test(email)); // false
Error: 오류 객체는 프로그램에서 발생하는 오류를 처리하는 데 사용됩니다.
** 예시 method : new Error(), throw
try {
throw new Error("Something went wrong!");
} catch (e) {
console.log(e.message); // 출력: "Something went wrong!"
}
브라우저 환경에서 사용되는 내장객체
Requirement
1. Provide a prompt to the user to enter a bill total.
2. Convert this user input to a number (don’t worry about error handling for non-numbers).
3. Calculate the tip amount assuming 10% (simply multiply the user input by 0.1). Use a const to define the 10% tip percentage.
4. Display the bill total and tip amount on the same console output line, for example,
let billTotal = prompt("Please enter the total bill : ");
//string --> float
billTotal = parseFloat(billTotal);
const tip = 0.1;
let tipTotal = billTotal * tip;
console.log(`For bill of ${billTotal} the tip should be ${tipTotal}`);
const country = "France";
const city = "Paris";
const population = 67;
const count = 2;
let msg = city + " is the capital of " + country;
// msg는 "Paris is the capital of France"로 설정됨.
msg += " Population of " + country + " is " + population;
// msg에 " Population of France is 67"이 추가되어 최종적으로 msg는
// "Paris is the capital of France Population of France is 67"이 됨.
let msg2 = population + count;
// msg2는 숫자 67 + 숫자 2 이므로 69가 됨.
// 콘솔에 출력
console.log(msg); // "Paris is the capital of France Population of France is 67"
console.log(msg2); // 69
const country = "France";
const city = "Paris";
let msg = `${city} is the capital of ${country}`;