null이라는 오직 하나의 값만 가짐
let lastName = null // null이 출력됨
undefined라는 오직 하나의 값만 가짐
let firstName // 선언 후 할당을 하지 않음
console.log(firstName) // undefined
논리 요소를 나타내며, true와 false 두 가지의 값을 가짐
조건문 또는 반복문에서 유용하게 사용
정수 또는 실수형 숫자를 표현하는 자료형
const a = 13
const b = -5
const c = 3.14 // float
const d = 2.998e8 // 2.998 * 10 ^ 8 = 299,800,000
const e = Infinity
const f = -Infinity
const g = NaN // Not a Number를 나타내는 값
문자열을 표현하는 자료형
const sentence1 = 'Ask and go to the blue' // 작은 따옴표
const sentence2 = "Ask and go to the blue" // 큰 따옴표
const firstName = 'Kim'
const lastName = 'SeoYeong'
const fullName = firstName + lastName
const word = "안녕
하세요" // Uncaught SyntaxError 발생
const word1 = "안녕 \n하세요" // 줄바꿈 됨
const word2 = `안녕
들 하세요`
const age = 10
const message = `홍길동은 ${age}세 입니다.`
유일한 값을 표현하는 자료형
const me = {
name:'jack',
phoneNumber:'01012345678',
'products': {
buds: 'Galaxy Buds pro',
galaxy: 'Galaxy s99',
},
}
console.log(me.name)
console.log(me['name'])
console.log(me['products'])
console.log(me.products) //불가능
console.log(me['products'].buds)
function 함수명(매개변수) {
// 동작
}
function add(num1, num2) {
return num1 + num2
}
add(2, 7) // 9
변수 키워드 함수명 = function (매개변수) {
// 동작
}
const sub = function(num1, num2) {
return num1 - num2
}
sub(7, 2) // 5